Add any traineddata file in tesseract and use in IOS

寵の児 提交于 2019-12-07 17:50:45

问题


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.



来源:https://stackoverflow.com/questions/21430947/add-any-traineddata-file-in-tesseract-and-use-in-ios

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!