在tesseract中添加任何traineddata文件并在IOS中使用

编程入门 行业动态 更新时间:2024-10-09 00:47:36
本文介绍了在tesseract中添加任何traineddata文件并在IOS中使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我能够编译已经在 tesseract 示例中的 ENGLISH 版本,但无法添加其他语言,如 ara.traineddata.

I am able to compile the ENGLISH version which is already in sample for tesseract but not able to add other language like ara.traineddata.

我喜欢

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

它可以识别 ENGLISH,但对于 ara 却报错

And it is recogninzing ENGLISH but for ara it is giving error

Error opening data file /Users/harshthakur/Library/Application Support/iPhone Simulator/7.0/Applications/3B0A1909-E1BA-45E9-99A0-FDEAB2CFF4E0/Documents/tessdata/ara.traineddata

请确保将 TESSDATA_PREFIX 环境变量设置为tessdata"目录的父目录.加载语言ara"失败

Please make sure the TESSDATA_PREFIX environment variable is set to the parent directory of your "tessdata" directory. Failed loading language 'ara'

将不胜感激任何帮助.

推荐答案

这是因为文档文件夹没有语言文件.将 ara.traineddata 文件复制到您的包中,并使用此代码将您的语言文件保存在文档文件夹中.然后再试一次.它会正常工作.

This is because the document folder does not have language file. Copy ara.traineddata file to your bundle and use this code to save your language file in document folder. Then try again. It will work fine.

- (void)storeLanguageFile {

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

这篇关于在tesseract中添加任何traineddata文件并在IOS中使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

更多推荐

[db:关键词]

本文发布于:2023-04-30 23:13:28,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1400873.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:并在   文件   tesseract   traineddata   IOS

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!