在tesseract中添加任何traineddata文件并在IOS中使用 [英] Add any traineddata file in tesseract and use in IOS

查看:20
本文介绍了在tesseract中添加任何traineddata文件并在IOS中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我能够编译已经在 tesseract 示例中的 ENGLISH 版本,但无法添加其他语言,如 ara.traineddata.

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.

我喜欢

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

它可以识别 ENGLISH,但对于 ara 却报错

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

请确保将 TESSDATA_PREFIX 环境变量设置为tessdata"目录的父目录.加载语言ara"失败

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

将不胜感激任何帮助.

推荐答案

这是因为文档文件夹没有语言文件.将 ara.traineddata 文件复制到您的包中,并使用此代码将您的语言文件保存在文档文件夹中.然后再试一次.它会正常工作.

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];
        }
}

这篇关于在tesseract中添加任何traineddata文件并在IOS中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆