gpt4 book ai didi

ios - Tesseract ios SDK 错误打开数据文件/tessdata/eng.traineddata

转载 作者:塔克拉玛干 更新时间:2023-11-01 21:45:56 24 4
gpt4 key购买 nike

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

pod 'TesseractOCRiOS', '3.4.0'

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

Error opening data file /tessdata/eng.traineddata Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language 'eng' Tesseract couldn't load any languages!

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

最佳答案

无论如何,我找到了解决方案。只需将 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;
}

关于ios - Tesseract ios SDK 错误打开数据文件/tessdata/eng.traineddata,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29445937/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com