This repository has been archived by the owner on Feb 12, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
/
OCRPlugin.m
82 lines (46 loc) · 1.91 KB
/
OCRPlugin.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//
// OCRPlugin.m
// pruebaTesseract
//
// Created by Admin on 09/06/12.
// Copyright (c) 2012 __MyCompanyName__. All rights reserved.
//
#import "OCRPlugin.h"
#import "claseAuxiliar.h"
@implementation OCRPlugin
@synthesize callbackID;
- (void) recogniseOCR:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options { //get the callback id
NSString *url_string = [options objectForKey:@"url_imagen"];
self.callbackID = [arguments pop];
claseAuxiliar *cA = [[claseAuxiliar alloc]init];
NSURL *url = [NSURL URLWithString:url_string];
NSData *data = [NSData dataWithContentsOfURL:url];
UIImage *Realimage = [[UIImage alloc] initWithData:data];
UIImage *newImage = [cA resizeImage:Realimage];
NSString *text = [cA ocrImage:newImage];
[self performSelectorOnMainThread:@selector(ocrProcessingFinished:)
withObject:text
waitUntilDone:NO];
[cA release];
}
- (void)ocrProcessingFinished:(NSString *)result
{
// Create Plugin Result
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK
messageAsString: result ];
// Checking if the string received is HelloWorld or not
if (result == nil
|| ([result respondsToSelector:@selector(length)]
&& [(NSData *)result length] == 0)
|| ([result respondsToSelector:@selector(count)]
&& [(NSArray *)result count] == 0))
{
// Call the Failure Javascript function
[self writeJavascript: [pluginResult toErrorCallbackString:self.callbackID]];
} else
{
// Call the Success Javascript function
[self writeJavascript: [pluginResult toSuccessCallbackString:self.callbackID]];
}
}
@end