Tesseract iOS除英语外的其他语言

Tesseract iOS除英语外的其他语言,ios,tesseract,Ios,Tesseract,我正在尝试使用Tesseract开源代码,看看我是否能在iPhone上编译和识别英文字符。我能够做到这一点。现在,我尝试在数据和更改中包含“ita.traineddata” tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding], // Path to tessdata-no ending /. "eng");

我正在尝试使用Tesseract开源代码,看看我是否能在iPhone上编译和识别英文字符。我能够做到这一点。现在,我尝试在数据和更改中包含“ita.traineddata”

tess->Init([dataPath cStringUsingEncoding:NSUTF8StringEncoding],    // Path to tessdata-no ending /.
           "eng");                                                  // ISO 639-3 string or NULL.

但我得到了这个错误:
打开数据文件/var/mobile/Applications/A37DB8B7-2272-4F80-9836-0034CEB56CC5/Documents/tessdata/ita.traineddata时出错


我遗漏了什么以及应该如何处理?

首先将tessdata添加到项目/项目名称文件夹,然后(重要的)转到目标/构建阶段/复制捆绑资源并添加tessdata文件夹作为参考

然后像这样初始化tesseract:

// 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], "ita");

注意:Tesseract默认使用英语进行初始化,一旦我删除了整个TesserData文件夹,它仍然可以在没有eng.traineddata文件的情况下工作,这就是为什么它可以使用英语而不能使用意大利语traineddata的原因,您的TesserData文件夹没有正确初始化。

如果您获得了Answare plz共享
// 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], "ita");