This exception happen when you trying to read text of image by using tessdata API’s. It try to get defalt path of environment variable TESSDATA_PREFIX in you application root diectory/tessdata/lang.traineddata. but if this folder and file not found then throw below exception.
Stacktrace
Exception in thread "main" java.lang.Error: Invalid memory access
at com.sun.jna.Native.invokePointer(Native Method)
at com.sun.jna.Function.invokePointer(Function.java:470)
at com.sun.jna.Function.invoke(Function.java:404)
at com.sun.jna.Function.invoke(Function.java:315)
at com.sun.jna.Library$Handler.invoke(Library.java:212)
at com.sun.proxy.$Proxy0.TessBaseAPIGetUTF8Text(Unknown Source)
at net.sourceforge.tess4j.Tesseract.getOCRText(Tesseract.java:437)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:292)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:213)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:197)
at com.fiot.ImageTextReading.crackImage(ImageTextReading.java:22)
at com.fiot.ImageTextReading.main(ImageTextReading.java:10)
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.
Failed loading language 'eng'
Tesseract couldn't load any languages!
Solutions
Follow these steps to resolve this issue:
- First download tessdata from this location https://github.com/tesseract-ocr/tessdata .
- Rename this unzip folder to tessdata.
- Copy this folder and paste it to your applciation root directory.
For all steps and environment setup follow this example: Java : Read Text from and Image Example
You must be logged in to post a comment.