[Solved] TESSDATA_PREFIX environment variable is set to the parent directory of your “tessdata” directory.


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:

  1. First download tessdata from this location https://github.com/tesseract-ocr/tessdata .
  2. Rename this unzip folder to tessdata.
  3. Copy this folder and paste it to your application root directory.

For all steps and environment setup follow this example: Java : Read Text from and Image Example

Advertisements
Advertisements

Your Feedback Motivate Us

If our FacingIssuesOnIT Experts solutions guide you to resolve your issues and improve your knowledge. Please share your comments, like and subscribe to get notifications for our posts.

Happy Learning !!!

2 thoughts on “[Solved] TESSDATA_PREFIX environment variable is set to the parent directory of your “tessdata” directory.”

Leave a comment