Tesseract 不使用路径变量
Tesseract not using path variable
为什么我的 Tesseract 实例要求我显式设置我的数据路径,但不想读取环境变量?
让我澄清一下:运行代码
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.
我已经设置了我的环境变量,即做
echo $TESSDATA_PREFIX returns /usr/share/tessdata/
现在,在我的代码中明确设置路径变量,即:
Itesseract tesseract = new Tesseract();
tesseract.setDatapath("/usr/share/tessdata/");
String result = tesseract.doOCR(myImage);
工作完美。为什么?
我正在使用 Manjaro 17.0.5
该库最初设计为使用捆绑在其 tessdata
文件夹中的数据文件。在你的例子中,如果你想从标准 tessdata
目录中读取,你需要按如下方式设置数据路径:
tesseract.setDatapath(System.getenv("TESSDATA_PREFIX"));
为什么我的 Tesseract 实例要求我显式设置我的数据路径,但不想读取环境变量?
让我澄清一下:运行代码
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.
我已经设置了我的环境变量,即做
echo $TESSDATA_PREFIX returns /usr/share/tessdata/
现在,在我的代码中明确设置路径变量,即:
Itesseract tesseract = new Tesseract();
tesseract.setDatapath("/usr/share/tessdata/");
String result = tesseract.doOCR(myImage);
工作完美。为什么? 我正在使用 Manjaro 17.0.5
该库最初设计为使用捆绑在其 tessdata
文件夹中的数据文件。在你的例子中,如果你想从标准 tessdata
目录中读取,你需要按如下方式设置数据路径:
tesseract.setDatapath(System.getenv("TESSDATA_PREFIX"));