Reputation: 1416
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
Upvotes: 0
Views: 2807
Reputation: 8345
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"));
Upvotes: 1