【问题标题】:Tesseract ios SDK Error opening data file /tessdata/eng.traineddataTesseract ios SDK 打开数据文件 /tessdata/eng.traineddata 时出错
【发布时间】:2015-06-09 08:31:27
【问题描述】:

我正在开发一个带有 openCV 和 Tesseract 框架的应用程序。 它在“无 64 位支持”的情况下运行良好,但苹果现在在每个版本中都需要 64 位支持。 所以我已经将 tesseract 框架更新为

pod 'TesseractOCRiOS', '3.4.0'

在我的项目中。 现在项目在所有设备上运行良好。 但是当我扫描任何图像时,我总是会遇到以下错误:

错误打开数据文件 /tessdata/eng.traineddata 请确保 TESSDATA_PREFIX 环境变量设置为的父目录 你的“tessdata”目录。加载语言“eng”Tesseract 失败 无法加载任何语言!

我浏览了谷歌上的每个链接,但没有成功。 我可以确保在我的项目中添加了“tessdata”文件夹作为文件夹引用。

【问题讨论】:

    标签: ios ocr tesseract scanning


    【解决方案1】:

    无论如何,我得到了解决方案。 只需将 pod 更新到最新版本,这样您的 pod 文件应该如下所示

    pod 'TesseractOCRiOS', '4.0.0'

    如果在文档目录中找不到“tessdata”,它会自动管理。您只需确保它存在于您的应用程序包中。

    然后你可以像这样初始化它

    _tesseract = new tesseract::TessBaseAPI();
    _tesseract->Init([[self pathToLangugeFIle] cStringUsingEncoding:NSUTF8StringEncoding], "eng");
    

    函数应该是这样的

    - (NSString*) pathToLangugeFIle{
    
        // Set up the tessdata path. This is included in the application bundle
        // but is copied to the Documents directory on the first run.
        NSArray *documentPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *documentPath = ([documentPaths count] > 0) ? [documentPaths objectAtIndex:0] : nil;
    
        NSString *dataPath = [documentPath stringByAppendingPathComponent:@"tessdata"];
        NSFileManager *fileManager = [NSFileManager defaultManager];
        // If the expected store doesn't exist, copy the default store.
        if (![fileManager fileExistsAtPath:dataPath]) {
            // get the path to the app bundle (with the tessdata dir)
            NSString *bundlePath = [[NSBundle mainBundle] bundlePath];
            NSString *tessdataPath = [bundlePath stringByAppendingPathComponent:@"tessdata"];
            if (tessdataPath) {
                [fileManager copyItemAtPath:tessdataPath toPath:dataPath error:NULL];
            }
        }
    
        setenv("TESSDATA_PREFIX", [[documentPath stringByAppendingString:@"/"] UTF8String], 1);
    
        return dataPath;
    }
    

    【讨论】:

      猜你喜欢
      • 2016-05-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-02-10
      • 1970-01-01
      • 2013-04-26
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多