gpt4 book ai didi

ios - Tessdata未复制到文档目录中

转载 作者:行者123 更新时间:2023-12-01 17:53:56 25 4
gpt4 key购买 nike

我正在使用以下方法在我的项目中添加经过tesseract训练的数据

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
// 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);

// init the tesseract engine.
tesseract = new tesseract::TessBaseAPI();
tesseract->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], "eng");
}
return self;
}

得到以下错误
Error opening data file /Users/frf/Library/Application Support/
iPhone Simulator/6.1/Applications/686F83C8-526C-47FB-9F02-
E44FBE69F60B/Documents/tessdata/eng.traineddata

tessdata未复制到文档目录中。我该怎么办 ?

请建议编辑我上面的代码...

最佳答案

我假设tessdata目录不存在。
在用户/文档目录中。

关于ios - Tessdata未复制到文档目录中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21722202/

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