File tree Expand file tree Collapse file tree 8 files changed +31
-19
lines changed
Template Framework Project/Template Framework Project
TestsProject/TestsProjectTests Expand file tree Collapse file tree 8 files changed +31
-19
lines changed Original file line number Diff line number Diff line change @@ -42,14 +42,12 @@ -(void)recognizeImageWithTesseract:(UIImage *)image
4242 self.imageToRecognize .image = bwImage;
4343
4444 // Create a new `G8RecognitionOperation` to perform the OCR asynchronously
45- G8RecognitionOperation *operation = [[G8RecognitionOperation alloc ] init ];
46-
4745 // It is assumed that there is a .traineddata file for the language pack
4846 // you want Tesseract to use in the "tessdata" folder in the root of the
4947 // project AND that the "tessdata" folder is a referenced folder and NOT
5048 // a symbolic group in your project
51- operation. tesseract . language = @" eng" ;
52-
49+ G8RecognitionOperation * operation = [[G8RecognitionOperation alloc ] initWithLanguage: @" eng" ] ;
50+
5351 // Use the original Tesseract engine mode in performing the recognition
5452 // (see G8Constants.h) for other engine mode options
5553 operation.tesseract .engineMode = G8OCREngineModeTesseractOnly;
Original file line number Diff line number Diff line change @@ -61,4 +61,18 @@ typedef void(^G8RecognitionOperationCallback)(G8Tesseract *tesseract);
6161// / @deprecated Use property recognitionCompleteBlock instead
6262@property (copy ) void (^completionBlock)(void ) DEPRECATED_ATTRIBUTE;
6363
64+ // / The default initializer should not be used since the language Tesseract
65+ // / uses needs to be explicit.
66+ - (instancetype )init __attribute__((unavailable(" Use initWithLanguage:language instead" )));
67+
68+ /* *
69+ * Initialize a G8RecognitionOperation with the provided language.
70+ *
71+ * @param language The language to use in recognition.
72+ *
73+ * @return The initialized G8RecognitionOperation object, or `nil` if there
74+ * was an error.
75+ */
76+ - (id )initWithLanguage : (NSString *)language ;
77+
6478@end
Original file line number Diff line number Diff line change @@ -20,11 +20,11 @@ @interface G8RecognitionOperation() <G8TesseractDelegate>
2020
2121@implementation G8RecognitionOperation
2222
23- - (id )init
23+ - (id ) initWithLanguage : ( NSString *) language
2424{
2525 self = [super init ];
2626 if (self != nil ) {
27- _tesseract = [[G8Tesseract alloc ] init ];
27+ _tesseract = [[G8Tesseract alloc ] initWithLanguage: language ];
2828 _tesseract.delegate = self;
2929
3030 __weak __typeof (self) weakSelf = self;
Original file line number Diff line number Diff line change @@ -243,6 +243,10 @@ extern NSInteger const kG8MaxCredibleResolution;
243243 */
244244@property (nonatomic , weak ) id <G8TesseractDelegate> delegate;
245245
246+ // / The default initializer should not be used since the language Tesseract
247+ // / uses needs to be explicit.
248+ - (instancetype )init __attribute__((unavailable(" Use initWithLanguage:language instead" )));
249+
246250/* *
247251 * Initialize Tesseract with the provided language.
248252 *
Original file line number Diff line number Diff line change @@ -80,11 +80,6 @@ + (void)clearCache
8080 tesseract::TessBaseAPI::ClearPersistentCache ();
8181}
8282
83- - (id )init
84- {
85- return [self initWithLanguage: nil ];
86- }
87-
8883- (id )initWithLanguage : (NSString *)language
8984{
9085 return [self initWithLanguage: language configDictionary: nil configFileNames: nil cachesRelatedDataPath: nil engineMode: G8OCREngineModeTesseractOnly];
Original file line number Diff line number Diff line change @@ -51,7 +51,7 @@ - (void)waitTimeLmit:(NSTimeInterval)maximumWait whileTrue:(BOOL (^)())shouldKee
5151- (void )setupTesseract
5252{
5353 if (self.tesseract == nil ) {
54- self.tesseract = [[G8Tesseract alloc ] init ];
54+ self.tesseract = [[G8Tesseract alloc ] initWithLanguage: @" eng " ];
5555 }
5656
5757 self.tesseract .delegate = self;
@@ -79,7 +79,7 @@ - (void)setupImage
7979
8080- (void )recognizeImage
8181{
82- self.tesseract = [[G8Tesseract alloc ] init ];
82+ self.tesseract = [[G8Tesseract alloc ] initWithLanguage: kG8Languages ];
8383 [self setupTesseract ];
8484 [self setupImage ];
8585
@@ -88,7 +88,7 @@ - (void)recognizeImage
8888
8989- (void )recognizeImageUsingOperation
9090{
91- G8RecognitionOperation *operation = [[G8RecognitionOperation alloc ] init ];
91+ G8RecognitionOperation *operation = [[G8RecognitionOperation alloc ] initWithLanguage: kG8Languages ];
9292 self.tesseract = operation.tesseract ;
9393 [self setupTesseract ];
9494
@@ -119,7 +119,7 @@ - (void)recognizeImageUsingOperation
119119
120120- (UIImage *)thresholdedImageForImage : (UIImage *)sourceImage
121121{
122- self.tesseract = [[G8Tesseract alloc ] init ];
122+ self.tesseract = [[G8Tesseract alloc ] initWithLanguage: kG8Languages ];
123123 [self setupTesseract ];
124124
125125 self.tesseract .image = [sourceImage g8_blackAndWhite ];
Original file line number Diff line number Diff line change @@ -66,7 +66,7 @@ - (BOOL)resetEngine;
6666 it (@" Should not raise on cache clearing" , ^{
6767 //
6868 for (int i = 0 ; i <= 10 ; i++) {
69- G8RecognitionOperation *operation = [[G8RecognitionOperation alloc ] init ];
69+ G8RecognitionOperation *operation = [[G8RecognitionOperation alloc ] initWithLanguage: kG8Languages ];
7070 operation.tesseract .image = [UIImage imageNamed: @" well_scaned_page" ];
7171 operation.tesseract .language = kG8Languages ;
7272
@@ -99,11 +99,11 @@ - (BOOL)resetEngine;
9999 [[tesseract shouldNot ] beNil ];
100100 NSAssert ([tesseract respondsToSelector: @selector (configEngine )] == YES , @" Error! G8Tesseract instance does not contain configEngine selector" );
101101 [[tesseract should ] receive: @selector (configEngine ) andReturn: theValue (NO )];
102- tesseract = [tesseract init ];
102+ tesseract = [tesseract initWithLanguage: kG8Languages ];
103103
104104 [[tesseract should ] beNil ];
105105
106- tesseract = [[G8Tesseract alloc ] init ];
106+ tesseract = [[G8Tesseract alloc ] initWithLanguage: kG8Languages ];
107107 NSAssert ([tesseract respondsToSelector: @selector (resetEngine )] == YES , @" Error! G8Tesseract instance does not contain resetEngine selector" );
108108 [[tesseract should ] receive: @selector (configEngine ) andReturn: theValue (NO )];
109109 [[theValue ([tesseract resetEngine ]) should ] beNo ];
Original file line number Diff line number Diff line change 1313
1414#import " G8RecognitionTestsHelper.h"
1515#import " UIImage+G8Equal.h"
16+ #import " Defaults.h"
1617
1718SPEC_BEGIN (RecognitionTests)
1819
288289 });
289290
290291 it (@" Should return nil without prerecognition" , ^{
291- G8Tesseract *tesseract = [[G8Tesseract alloc ] init ];
292+ G8Tesseract *tesseract = [[G8Tesseract alloc ] initWithLanguage: kG8Languages ];
292293
293294 NSString *hOCR = [tesseract recognizedHOCRForPageNumber: 0 ];
294295 [[hOCR should ] beNil ];
You can’t perform that action at this time.
0 commit comments