Java Tess4J:无效的内存访问

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19894890/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-12 21:08:01  来源:igfitidea点击:

Tess4J: Invalid memory access

javaocrtesseract

提问by user2141969

I am trying to use Tess4J in my project to extract text from an image. I am getting the following error when I try run the OCR: Exception in thread "main" java.lang.Error: Invalid memory access

我试图在我的项目中使用 Tess4J 从图像中提取文本。当我尝试运行 OCR 时出现以下错误:线程“main”中的异常 java.lang.Error: Invalid memory access

    try {
        File imageFile = new File("example4.jpg");
        Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
        //Tesseract1 instance = new Tesseract1();
        String result = instance.doOCR(imageFile);
        System.out.println(result);
    } catch (Exception e) {
        e.printStackTrace();
    }   

回答by Renjitha

if you are running on 32 bit JVM

如果您在 32 位 JVM 上运行

Please try with Tesseract1 instance = new Tesseract1();

请尝试使用 Tesseract1 instance = new Tesseract1();

instead of using Tesseract instance = Tesseract.getInstance();

而不是使用 Tesseract instance = Tesseract.getInstance();

回答by fanky

you can set the data path i am getting same problem when i set the data path that problem is solved
try try this

你可以设置数据路径,当我设置问题解决的数据路径时,我遇到了同样的问题,
试试这个

instance1.setDatapath("D://Hotel_project//Tess4J-1.2-src//Tess4J//tessdata");

instance1.setDatapath("D://Hotel_project//Tess4J-1.2-src//Tess4J//tessdata");

回答by aglour

You must define the datapath of the traineddata to use. If you don't specify the language it will assume it is eng.

您必须定义要使用的训练数据的数据路径。如果您不指定语言,它将假定它是 eng。

For instance, it your project path is PROJECT and your trained data is at PROJECT/data/tessdata/eng.traineddata

例如,你的项目路径是 PROJECT,你的训练数据在 PROJECT/data/tessdata/eng.traineddata

tess.setDatapath("data");
tess.setLanguage("eng");

Remember that "tessdata" shoundn't be in the path you specify

请记住,“tessdata”不应出现在您指定的路径中