Tesseract not using path variable

流过昼夜 提交于 2019-12-11 16:06:29

问题


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);

Throws an error:

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);

WORKS PERFECTLY. Why? I'm using Manjaro 17.0.5


回答1:


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"));



来源:https://stackoverflow.com/questions/46725776/tesseract-not-using-path-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!