Skip to content

Commit c1e8be3

Browse files
author
Kirill Makankov
committed
more hOCR tests, which are in the hOCR.m file now.
1 parent ab958da commit c1e8be3

File tree

4 files changed

+77
-11
lines changed

4 files changed

+77
-11
lines changed

TestsProject/TestsProject.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
73BE4C091A598F47002C15F1 /* TesseractOCR.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 73C0A7BC1A59561F00D823D4 /* TesseractOCR.framework */; };
3232
73BE4C0A1A598F47002C15F1 /* TesseractOCR.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 73C0A7BC1A59561F00D823D4 /* TesseractOCR.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
3333
73BE4C311A5B404C002C15F1 /* well_scaned_page.hOCR in Resources */ = {isa = PBXBuildFile; fileRef = 73BE4C301A5B404C002C15F1 /* well_scaned_page.hOCR */; };
34+
73BE4C331A5BC8A6002C15F1 /* hOCR.m in Sources */ = {isa = PBXBuildFile; fileRef = 73BE4C321A5BC8A6002C15F1 /* hOCR.m */; };
35+
73BE4C351A5BD324002C15F1 /* image_sample.hOCR in Resources */ = {isa = PBXBuildFile; fileRef = 73BE4C341A5BD324002C15F1 /* image_sample.hOCR */; };
3436
8FA2F9CE23919BEC8C64A5EA /* libPods-TestsProjectTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CD3C116A45C293ADAC81D1B /* libPods-TestsProjectTests.a */; };
3537
/* End PBXBuildFile section */
3638

@@ -93,6 +95,8 @@
9395
732C54781A5288CC000322DA /* Defaults.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = Defaults.m; sourceTree = "<group>"; };
9496
736EFF231A5872CA0031B432 /* tessdata-rus */ = {isa = PBXFileReference; lastKnownFileType = folder; name = "tessdata-rus"; path = "TestsProjectTests/tessdata-rus"; sourceTree = SOURCE_ROOT; };
9597
73BE4C301A5B404C002C15F1 /* well_scaned_page.hOCR */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = well_scaned_page.hOCR; sourceTree = "<group>"; };
98+
73BE4C321A5BC8A6002C15F1 /* hOCR.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = hOCR.m; sourceTree = "<group>"; };
99+
73BE4C341A5BD324002C15F1 /* image_sample.hOCR */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = image_sample.hOCR; sourceTree = "<group>"; };
96100
73C0A7BC1A59561F00D823D4 /* TesseractOCR.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; path = TesseractOCR.framework; sourceTree = BUILT_PRODUCTS_DIR; };
97101
/* End PBXFileReference section */
98102

@@ -169,6 +173,7 @@
169173
4115B9771A3EF8E90004EC0A /* TestsProjectTests */ = {
170174
isa = PBXGroup;
171175
children = (
176+
73BE4C321A5BC8A6002C15F1 /* hOCR.m */,
172177
732C54751A514DA5000322DA /* InitializationTests.m */,
173178
4115B97A1A3EF8E90004EC0A /* RecognitionTests.m */,
174179
4115B9781A3EF8E90004EC0A /* Supporting Files */,
@@ -211,6 +216,7 @@
211216
41C68DB21A41849100848AE1 /* image_sample.jpg */,
212217
41C68DB41A41854600848AE1 /* image_sample_tr.png */,
213218
412E9EAC1A45872A007DDAA5 /* image_sample_bl.png */,
219+
73BE4C341A5BD324002C15F1 /* image_sample.hOCR */,
214220
4141211D1A4B1E3900583ED4 /* image_blank.png */,
215221
);
216222
name = Images;
@@ -311,6 +317,7 @@
311317
files = (
312318
412E9EAB1A44316C007DDAA5 /* well_scaned_page.png in Resources */,
313319
41C68DB31A41849100848AE1 /* image_sample.jpg in Resources */,
320+
73BE4C351A5BD324002C15F1 /* image_sample.hOCR in Resources */,
314321
4115B96C1A3EF8E90004EC0A /* Images.xcassets in Resources */,
315322
4115B9851A3EF9920004EC0A /* Launch Screen.xib in Resources */,
316323
4141211E1A4B1E3900583ED4 /* image_blank.png in Resources */,
@@ -380,6 +387,7 @@
380387
buildActionMask = 2147483647;
381388
files = (
382389
732C54791A5288CC000322DA /* Defaults.m in Sources */,
390+
73BE4C331A5BC8A6002C15F1 /* hOCR.m in Sources */,
383391
414121231A4C5A5700583ED4 /* G8RecognitionTestsHelper.m in Sources */,
384392
4115B97B1A3EF8E90004EC0A /* RecognitionTests.m in Sources */,
385393
732C54761A514DA6000322DA /* InitializationTests.m in Sources */,
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<div class='ocr_page' id='page_1' title='image ""; bbox 0 0 1121 156; ppageno 0'>
2+
<div class='ocr_carea' id='block_1_1' title="bbox 32 20 1091 148">
3+
<p class='ocr_par' dir='ltr' id='par_1_1' title="bbox 32 20 1091 148">
4+
<span class='ocr_line' id='line_1_1' title="bbox 32 20 1091 148; baseline -0.008 0"><span class='ocrx_word' id='word_1_1' title='bbox 32 20 1091 148; x_wconf 84' lang='eng'>1234567890</span>
5+
</span>
6+
</p>
7+
</div>
8+
</div>

TestsProject/TestsProjectTests/RecognitionTests.m

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -238,17 +238,6 @@
238238

239239
[[[[helper.tesseract recognizedBlocksByIteratorLevel:G8PageIteratorLevelWord] should] haveAtLeast:10] items];
240240
});
241-
242-
it(@"Should hOCR", ^{
243-
244-
[helper recognizeImage];
245-
NSString *hOCR = [helper.tesseract recognizedHOCRForPageNumber:0];
246-
247-
NSString *path = [[NSBundle mainBundle] pathForResource:@"well_scaned_page" ofType:@"hOCR"];
248-
NSError *error = nil;
249-
[[hOCR should] equal:[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]];
250-
NSAssert(error == nil, @"error loading hOCR from file %@: %@", path, error);
251-
});
252241
});
253242

254243
SPEC_END
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
//
2+
// hOCR.m
3+
// TestsProject
4+
//
5+
// Created by Kirill Makankov on 06.01.15.
6+
// Copyright (c) 2015 Daniele Galiotto - www.g8production.com. All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
#import <Kiwi/Kiwi.h>
11+
12+
#import "G8RecognitionTestsHelper.h"
13+
14+
SPEC_BEGIN(hOCRTests)
15+
16+
__block G8RecognitionTestsHelper *helper;
17+
18+
beforeEach(^{
19+
helper = [[G8RecognitionTestsHelper alloc] init];
20+
});
21+
22+
describe(@"hOCR", ^{
23+
24+
it(@"Should sample image", ^{
25+
26+
NSString *path = [[NSBundle mainBundle] pathForResource:@"image_sample" ofType:@"hOCR"];
27+
28+
helper.image = [UIImage imageNamed:@"image_sample.jpg"];
29+
helper.charWhitelist = @"0123456789";
30+
31+
[helper recognizeImage];
32+
NSString *hOCR = [helper.tesseract recognizedHOCRForPageNumber:0];
33+
34+
NSError *error = nil;
35+
[[hOCR should] equal:[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]];
36+
NSAssert(error == nil, @"error loading hOCR from file %@: %@", path, error);
37+
});
38+
39+
it(@"Should well scanced page", ^{
40+
41+
NSString *path = [[NSBundle mainBundle] pathForResource:@"well_scaned_page" ofType:@"hOCR"];
42+
43+
helper.image = [UIImage imageNamed:@"well_scaned_page"];
44+
45+
[helper recognizeImage];
46+
NSString *hOCR = [helper.tesseract recognizedHOCRForPageNumber:0];
47+
48+
NSError *error = nil;
49+
[[hOCR should] equal:[NSString stringWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&error]];
50+
NSAssert(error == nil, @"error loading hOCR from file %@: %@", path, error);
51+
});
52+
53+
it(@"Should return nil without prerecognition", ^{
54+
G8Tesseract *tesseract = [[G8Tesseract alloc] init];
55+
56+
NSString *hOCR = [tesseract recognizedHOCRForPageNumber:0];
57+
[[hOCR should] beNil];
58+
});
59+
});
60+
61+
SPEC_END

0 commit comments

Comments
 (0)