|
84 | 84 | tesseract.sourceResolution = sourceResolution; |
85 | 85 | } |
86 | 86 |
|
87 | | - __block BOOL isDone = NO; |
88 | | - dispatch_async(dispatch_get_global_queue(QOS_CLASS_UTILITY, 0), ^{ |
89 | | - [tesseract recognize]; |
90 | | - isDone = YES; |
91 | | - }); |
92 | | - |
93 | | - wait(maxExpectedRecognitionTime, ^{ |
94 | | - return (BOOL)(isDone == NO); |
95 | | - }); |
96 | | - |
97 | | - if (isDone == NO) { |
98 | | - [NSException raise:@"Tesseract stopped" format:@"Tesseract worked too long"]; |
99 | | - } |
| 87 | + [tesseract recognize]; |
100 | 88 | }; |
101 | 89 |
|
102 | 90 | void (^recognizeImageUsingOperation)() = ^{ |
|
147 | 135 | it(@"Should recognize sync", ^{ |
148 | 136 | [[theBlock(recognizeImage) shouldNot] raise]; |
149 | 137 |
|
| 138 | + [[theValue(tesseract.progress) should] equal:theValue(100)]; |
| 139 | + |
150 | 140 | NSString *recognizedText = tesseract.recognizedText; |
151 | 141 | [[recognizedText should] containString:@"1234567890"]; |
152 | 142 | }); |
153 | 143 |
|
154 | 144 | it(@"Should recognize by queue", ^{ |
155 | 145 | [[theBlock(recognizeImageUsingOperation) shouldNot] raise]; |
156 | 146 |
|
| 147 | + [[theValue(tesseract.progress) should] equal:theValue(100)]; |
| 148 | + |
157 | 149 | NSString *recognizedText = tesseract.recognizedText; |
158 | 150 | [[recognizedText should] containString:@"1234567890"]; |
159 | 151 | }); |
|
231 | 223 | }); |
232 | 224 |
|
233 | 225 | it(@"Should draw blocks on image", ^{ |
234 | | - [[theBlock(recognizeImageUsingOperation) shouldNot] raise]; |
| 226 | + [[theBlock(recognizeImage) shouldNot] raise]; |
235 | 227 |
|
236 | 228 | NSArray *blocks = [tesseract confidencesByIteratorLevel:G8PageIteratorLevelSymbol]; |
237 | 229 | UIImage *blocksImage = [tesseract imageWithBlocks:blocks drawText:YES thresholded:NO]; |
|
289 | 281 |
|
290 | 282 | describe(@"Well scaned page", ^{ |
291 | 283 |
|
| 284 | + static NSString *const kG8WellScanedFirstTitle = @"Foreword"; |
| 285 | + static NSString *const kG8WellScanedFinalLongString = @"recommendations sometimes get acted on"; |
| 286 | + |
292 | 287 | beforeEach(^{ |
293 | 288 | image = [UIImage imageNamed:@"well_scaned_page"]; |
294 | 289 | rect = (CGRect){CGPointZero, image.size}; |
|
297 | 292 | it(@"Should recognize", ^{ |
298 | 293 | [[theBlock(recognizeImage) shouldNot] raise]; |
299 | 294 |
|
| 295 | + [[theValue(tesseract.progress) should] equal:theValue(100)]; |
| 296 | + |
300 | 297 | NSString *recognizedText = tesseract.recognizedText; |
301 | | - [[recognizedText should] containString:@"Foreword"]; |
| 298 | + [[recognizedText should] containString:kG8WellScanedFirstTitle]; |
| 299 | + [[recognizedText should] containString:kG8WellScanedFinalLongString]; |
| 300 | + |
302 | 301 | [[recognizedText should] containString:@"Division"]; |
303 | 302 | [[recognizedText should] containString:@"remove"]; |
304 | 303 | [[recognizedText should] containString:@"1954"]; |
|
314 | 313 | it(@"Should analyze layout", ^{ |
315 | 314 | pageSegmentationMode = G8PageSegmentationModeAutoOSD; |
316 | 315 |
|
317 | | - [[theBlock(recognizeImageUsingOperation) shouldNot] raise]; |
| 316 | + [[theBlock(recognizeImage) shouldNot] raise]; |
318 | 317 |
|
319 | 318 | CGFloat deskewAngle = tesseract.deskewAngle; |
320 | 319 | [[theValue(ABS(deskewAngle)) should] beGreaterThan:theValue(FLT_EPSILON)]; |
|
325 | 324 | }); |
326 | 325 |
|
327 | 326 | it(@"Should break by deadline", ^{ |
328 | | - waitDeadline = 2.0; |
| 327 | + waitDeadline = 1.0; |
329 | 328 |
|
330 | 329 | [[theBlock(recognizeImageUsingOperation) shouldNot] raise]; |
331 | 330 |
|
332 | 331 | [[tesseract shouldNot] beNil]; |
| 332 | + [[theValue(tesseract.progress) should] beLessThan:theValue(100)]; |
| 333 | + |
333 | 334 | NSString *recognizedText = tesseract.recognizedText; |
334 | | - [[recognizedText should] containString:@"Foreword"]; |
335 | | - [[recognizedText shouldNot] containString:@"Mathematcs"]; |
| 335 | + [[recognizedText should] containString:kG8WellScanedFirstTitle]; |
| 336 | + [[recognizedText shouldNot] containString:kG8WellScanedFinalLongString]; |
336 | 337 | [[[[tesseract confidencesByIteratorLevel:G8PageIteratorLevelWord] should] haveAtLeast:10] items]; |
337 | 338 | }); |
338 | 339 |
|
|
0 commit comments