I have been testing Tesseract on Xcode.I followed instructions from Visit http://lois.di-qual.net/blog/install-and-use-tesseract-on-ios-with-tesseract-ios/ .But the problem
Its because your document folder does not contain language file. Use the code below to save language file which added in bundle to document folder. call this method before you initiate tesseract Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata" language:@"eng"];
- (void)storeLanguageFile {
NSFileManager *fileManager = [NSFileManager defaultManager];
NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
NSString *path = [docsDirectory stringByAppendingPathComponent:@"/tessdata/eng.traineddata"];
if(![fileManager fileExistsAtPath:path])
{
NSData *data = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/tessdata/eng.traineddata"]];
NSError *error;
[[NSFileManager defaultManager] createDirectoryAtPath:[docsDirectory stringByAppendingPathComponent:@"/tessdata"] withIntermediateDirectories:YES attributes:nil error:&error];
[data writeToFile:path atomically:YES];
}
}
- (NSString *)scanImage:(UIImage *)image {
Tesseract *tesseract = [[Tesseract alloc] initWithDataPath:@"/tessdata" language:@"eng"];
[tesseract setVariableValue:@"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" forKey:@"tessedit_char_whitelist"];
[tesseract setVariableValue:@".,:;'" forKey:@"tessedit_char_blacklist"];
if (image) {
[tesseract setImage:image];
[tesseract setRect:CGRectMake(0, point.y- 25, image.size.width, 50)];
[tesseract recognize];
return [tesseract recognizedText];
}
return nil;
}
After adding TESSDATA_PREFIX to your system variables, try restarting your PC. I'm running Windows 10 and that's what fixed this error for me.
After days of searching for the solution, none of the proposed solutions worked for me because I am using objective C++ in xcode. But after tons of experimentations, for anyone that still need this solved, the solution is a 1-liner (if ure using TessBaseAPI), before api.init(...) add G8Tesseract *tesseract = [[G8Tesseract alloc] initWithLanguage:@"eng"]; This magically gets rid of the TESSDATA_PREFIX error