Tesseract不使用路径变量 [英] Tesseract not using path variable

查看:219
本文介绍了Tesseract不使用路径变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么我的Tesseract实例要求我显式设置数据路径,但又不想读取环境变量?

Why does my Tesseract instance require me to explicitly set my datapath, but doesn't want to read the environment variable?

让我澄清一下:运行代码

Let me clarify: running the code

ITesseract tesseract = new Tesseract();
String result = tesseract.doOCR(myImage);

引发错误:

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.

我已经设置了环境变量,即正在执行

I already have set my environment variable, ie doing

echo $TESSDATA_PREFIX returns /usr/share/tessdata/

现在,在我的代码中显式设置路径变量,即:

Now, setting the path variable explicitly in my code, ie:

Itesseract tesseract = new Tesseract();
tesseract.setDatapath("/usr/share/tessdata/");
String result = tesseract.doOCR(myImage);

可以正常工作.为什么? 我正在使用Manjaro 17.0.5

WORKS PERFECTLY. Why? I'm using Manjaro 17.0.5

推荐答案

该库最初旨在使用捆绑在其tessdata文件夹中的数据文件.对于您的情况,如果要从标准tessdata目录中读取,则需要按以下方式设置数据路径:

The library was initially designed to use the data files bundled in its tessdata folder. In your case, if you want to read from the standard tessdata directory, you would want to set datapath as follows:

tesseract.setDatapath(System.getenv("TESSDATA_PREFIX"));

这篇关于Tesseract不使用路径变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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