qq_18093047
qq_18093047
采纳率100%
2015-11-19 21:06 阅读 17.1k
已采纳

Tesseract OCR - tess4j tessdata目录设置问题

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

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

3条回答 默认 最新

  • 已采纳
    qq_18093047 qq_18093047 2015-11-19 21:22

    自己解决了,虽然绕了一步,提供出来参考
    instance.setDatapath("youdir");
    看官网教程没这步,是哪里设置不对,有知道的说一下

    点赞 6 评论 复制链接分享
  • qq_37639650 qq_37639650 2017-11-02 08:35

    我设置了还是这个错

    点赞 评论 复制链接分享
  • qq_41475316 __BlueCat 2019-04-04 11:13

    run configuration中设置TESSDATA_PREFIX 这个怎么设置的?

    点赞 评论 复制链接分享

相关推荐