-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtessocr.mm
56 lines (43 loc) · 1.41 KB
/
tessocr.mm
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
//
// tesseract.m
// dsptest1
//
// Created by Lieven Govaerts on 14/04/12.
// Copyright 2012 __MyCompanyName__. All rights reserved.
//
#import "tessocr.h"
#include "util.h"
@implementation tessocr
- (char*)run_tesseract:(const conn_box_t *)box;
{
int width = box->xmax - box->xmin + 1;
int height = box->ymax - box->ymin + 1;
dsptest_log(LOG_OCR, __FILE__,
"Pass image in bounding box (%d,%d)-(%d,%d) to TesseractRect.\n",
box->xmin, box->ymin, box->xmin+width, box->ymin+height);
// this could take a while. maybe needs to happen asynchronously.
char* text = tess->TesseractRect(box->img, 1, width,
0, 0, width, height);
return text;
}
-(id)init
{
if (self = [super init]) {
NSString* dataPath = [[[NSBundle bundleForClass:[tessocr class]] bundlePath] stringByAppendingString:@"/Contents/Resources/"];
// NSString* dataPath = @"/Users/lgo/macdev/tesseract-ocr/tessdata";
// NSString *dataPathWithSlash = [dataPath stringByAppendingString:@"/"];
const char* dataPathDirectoryCString = [dataPath cStringUsingEncoding:NSUTF8StringEncoding];
setenv("TESSDATA_PREFIX", dataPathDirectoryCString, 1);
// setenv("TESSDATA_PREFIX", [dataPathWithSlash UTF8String], 1);
// init the tesseract engine.
tess = new TessBaseAPI();
tess->Init(dataPathDirectoryCString, "eng");
}
return self;
}
-(void)dealloc
{
tess->End();
[super dealloc];
}
@end