Tesseract在Xcode上运行错误 [英] Tesseract running error on Xcode

查看:294
本文介绍了Tesseract在Xcode上运行错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在Xcode上测试Tesseract.I按照访问 http://lois.di-qual.net/blog/install-and-use-tesseract-on-ios-with-tesseract-ios/ 。但问题是我跑的时候程序我在控制台上收到以下错误:

I have been testing Tesseract on Xcode.I followed instructions from Visit http://lois.di-qual.net/blog/install-and-use-tesseract-on-ios-with-tesseract-ios/ .But the problem is that when i run the program i get the following errors on console:

Error opening data file /Users/mdriduanulislam/Library/Application Support/iPhone 
Simulator/7.0/Applications/0ABCEAB3-3793-44C9-8914-
A99BB6B4EF9F/Documents/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!`

我在StackOveflow上遇到了1个问题,但答案并不令人满意。有人请告诉我为什么会出现问题以及问题的可能解决方案。我急切地等待正确答案请。

I have 1 problem which was been asked on StackOveflow but the answer was not satisfactory.Can someone please tell me why the problem is happening and the possible solution for the problem please.I'm eagerly waiting for right answer please.

推荐答案

因为您的文档文件夹不包含语言文件。使用下面的代码将捆绑添加到文档文件夹中的语言文件保存。在启动tesseract之前调用此方法 Tesseract * tesseract = [[Tesseract alloc] initWithDataPath:@tessdata语言:@eng];

Its because your document folder does not contain language file. Use the code below to save language file which added in bundle to document folder. call this method before you initiate tesseract Tesseract* tesseract = [[Tesseract alloc] initWithDataPath:@"tessdata" language:@"eng"];

- (void)storeLanguageFile {

        NSFileManager *fileManager = [NSFileManager defaultManager];
        NSString *docsDirectory = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0];
        NSString *path = [docsDirectory stringByAppendingPathComponent:@"/tessdata/eng.traineddata"];
        if(![fileManager fileExistsAtPath:path])
        {
            NSData *data = [NSData dataWithContentsOfFile:[[[NSBundle mainBundle] resourcePath] stringByAppendingString:@"/tessdata/eng.traineddata"]];
            NSError *error;
            [[NSFileManager defaultManager] createDirectoryAtPath:[docsDirectory stringByAppendingPathComponent:@"/tessdata"] withIntermediateDirectories:YES attributes:nil error:&error];
            [data writeToFile:path atomically:YES];
        }
}

- (NSString *)scanImage:(UIImage *)image {

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

        [tesseract setVariableValue:@"0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" forKey:@"tessedit_char_whitelist"];
        [tesseract setVariableValue:@".,:;'" forKey:@"tessedit_char_blacklist"];

        if (image) {
            [tesseract setImage:image];
            [tesseract setRect:CGRectMake(0, point.y- 25, image.size.width, 50)];
            [tesseract recognize];
            return [tesseract recognizedText];
        }
        return nil;
    }

这篇关于Tesseract在Xcode上运行错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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