eclipse 總說tessdata找不到
已在 run configuration中設置TESSDATA_PREFIX
public static void main(String[] args) {
System.out.println(new File(System.getenv("TESSDATA_PREFIX"),"./tessdata/eng.traineddata").exists());
File imageFile = new File("f:\\testocr.png");
ITesseract instance = new Tesseract(); // JNA Interface Mapping
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
true
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:429)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:284)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:205)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:189)
at com.cone.englishutill.OCRUtil.main(OCRUtil.java:18)
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!
AdaptedTemplates != NULL:Error:Assert failed:in file ....\classify\adaptmatch.cpp, line 174
自己解決了,雖然繞了一步,提供出來參考
instance.setDatapath("youdir");
看官網教程沒這步,是哪裡設置不對,有知道的說一下