Created
October 26, 2011 19:14
-
-
Save leogomes/1317471 to your computer and use it in GitHub Desktop.
Tesseract initialization
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-(void) startTesseract { | |
//Adapted from http://robertcarlsen.net/2009/12/06/ocr-on-iphone-demo-1043 | |
NSString *dataPath = [[self applicationDocumentsDirectory] stringByAppendingPathComponent:@"tessdata"]; | |
/* | |
Set up the data in the docs dir | |
want to copy the data to the documents folder if it doesn't already exist | |
*/ | |
NSFileManager *fileManager = [NSFileManager defaultManager]; | |
// If the expected store doesn't exist, copy the default store. | |
if (![fileManager fileExistsAtPath:dataPath]) { | |
// get the path to the app bundle (with the tessdata dir) | |
NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; | |
NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"]; | |
if (tessdataPath) { | |
[fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL]; | |
} | |
} | |
NSString *dataPathWithSlash = [[self applicationDocumentsDirectory] stringByAppendingString:@"/"]; | |
setenv("TESSDATA_PREFIX", [dataPathWithSlash UTF8String], 1); | |
// init the tesseract engine. | |
tess = new tesseract::TessBaseAPI(); | |
tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], // Path to tessdata-no ending /. | |
"fra"); // ISO 639-3 string or NULL. | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment