Add any traineddata file in tesseract and use in I

2019-05-14 00:36发布

问题:

I am able to compile the ENGLISH version which is already in sample for tesseract but not able to add other language like ara.traineddata.

I am doing like

 Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata" language:@"ara+eng"];

And it is recogninzing ENGLISH but for ara it is giving error

Error opening data file /Users/harshthakur/Library/Application Support/iPhone Simulator/7.0/Applications/3B0A1909-E1BA-45E9-99A0-FDEAB2CFF4E0/Documents/tessdata/ara.traineddata

Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language 'ara'

any help will be greatly appreciated.

回答1:

This is because the document folder does not have language file. Copy ara.traineddata file to your bundle and use this code to save your language file in document folder. Then try again. It will work fine.

- (void)storeLanguageFile {

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *path = [docsDirectory stringByAppendingPathComponent:@"/tessdata/ara.traineddata"];
        if(![fileManager fileExistsAtPath:path])
        {
            NSData *data = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/tessdata/ara.traineddata"]];
            NSError *error;
            [[NSFileManager defaultManager] createDirectoryAtPath:[docsDirectory stringByAppendingPathComponent:@"/tessdata"] withIntermediateDirectories:YES attributes:nil error:&error];
            [data writeToFile:path atomically:YES];
        }
}


回答2:

Have a look here ,maybe it will be helpful to you .

Tesseract

here you can

   -setLanguage:

  - (BOOL)setLanguage:(NSString *)language

Override the language defined with -initWithDataPath:language:.



回答3:

You probably need ara.cube.* files also.

Flipping the order of the languages could improve recognition rates, once you get it to run.



标签: ios tesseract