Add any traineddata file in tesseract and use in I

2019-05-14 00:50发布

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.

标签: ios tesseract
3条回答
Evening l夕情丶
2楼-- · 2019-05-14 01:06

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:.

查看更多
\"骚年 ilove
3楼-- · 2019-05-14 01:09

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];
        }
}
查看更多
成全新的幸福
4楼-- · 2019-05-14 01:18

You probably need ara.cube.* files also.

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

查看更多
登录 后发表回答