Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/224.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/maven/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 安卓:Tesseract无法';不要加载任何语言_Android_Maven_Tesseract_Tess4j - Fatal编程技术网

Android 安卓:Tesseract无法';不要加载任何语言

Android 安卓:Tesseract无法';不要加载任何语言,android,maven,tesseract,tess4j,Android,Maven,Tesseract,Tess4j,大家好,我正在尝试运行Tesseract并从图像中获取文本,但遇到以下错误: 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:477) at com.sun.jna.Function.invoke(Functi

大家好,我正在尝试运行Tesseract并从图像中获取文本,但遇到以下错误:

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:477)
at com.sun.jna.Function.invoke(Function.java:411)
at com.sun.jna.Function.invoke(Function.java:323)
at com.sun.jna.Library$Handler.invoke(Library.java:236)
at com.sun.proxy.$Proxy0.TessBaseAPIGetUTF8Text(Unknown Source)
at net.sourceforge.tess4j.Tesseract.getOCRText(Tesseract.java:436)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:291)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:196)
at Crop_Image.main(Crop_Image.java:98)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)
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!
我正在加载一个包含英文文本的图像文件
jpg
。这是我尝试加载文件然后尝试从中获取文本的方式:

 public static void main(String[] args){

    String result = "";

    File imageFile = new File("C:\\Users\\user\\Desktop\\Untitled.jpg");
    Tesseract instance = new Tesseract();

    try {
         result = instance.doOCR(imageFile);
         result.toString();

    } catch (Exception e) {
        e.printStackTrace();
        System.err.println(e.getMessage());
    }
}
此外,我还在我的项目中使用
Maven
,这是我的
pom
文件:

<dependencies>

    <dependency>
        <groupId>nu.pattern</groupId>
        <artifactId>opencv</artifactId>
        <version>2.4.9-4</version>
    </dependency>

    <dependency>
        <groupId>net.sourceforge.tess4j</groupId>
        <artifactId>tess4j</artifactId>
        <version>3.1.0</version>
    </dependency>

</dependencies>

nu.pattern
opencv
2.4.9-4
net.sourceforge.4j
tess4j
3.1.0

这一错误的原因可能是什么

您需要将
instance.setDatapath
设置为
tessdata
文件夹的父目录

File tessDataFolder = LoadLibs.extractTessResources("tessdata"); // Maven build bundles English data
instance.setDatapath(tessDataFolder.getParent());

请参阅。

您需要将
instance.setDatapath
设置为
tessdata
文件夹的父目录

File tessDataFolder = LoadLibs.extractTessResources("tessdata"); // Maven build bundles English data
instance.setDatapath(tessDataFolder.getParent());

请参阅。

我看到了您的代码,您初始化
teseract
的方式可能有问题。现在,由于您使用的是nguyenq建议的
maven
,因此您需要准确地指向库的位置-
tessdata
,因此以下是您应该做的:

  public static String Image_To_Text(String image_path){

    String result = "";

    File imageFile = new File("your path to your image");

    Tesseract instance = Tesseract.getInstance();
    //In case you don't have your own tessdata, let it also be extracted for you
    File tessDataFolder = LoadLibs.extractTessResources("tessdata");

    //Set the tessdata path
    instance.setDatapath(tessDataFolder.getAbsolutePath());

    try {
         result = instance.doOCR(imageFile);

    } catch (Exception e) {
        e.printStackTrace();            
    }

    return result;
}

我看到了您的代码,您初始化
teseract
的方式可能有问题。现在,由于您使用的是nguyenq建议的
maven
,因此您需要准确地指向库的位置-
tessdata
,因此以下是您应该做的:

  public static String Image_To_Text(String image_path){

    String result = "";

    File imageFile = new File("your path to your image");

    Tesseract instance = Tesseract.getInstance();
    //In case you don't have your own tessdata, let it also be extracted for you
    File tessDataFolder = LoadLibs.extractTessResources("tessdata");

    //Set the tessdata path
    instance.setDatapath(tessDataFolder.getAbsolutePath());

    try {
         result = instance.doOCR(imageFile);

    } catch (Exception e) {
        e.printStackTrace();            
    }

    return result;
}

是的,我计算了那么多,但我使用的是
maven
,所以即使我指向
.jar
文件的目录,也是同样的错误。@nguyenq嗨,nguyen!我非常喜欢你的产品Vietor使用tesseract。我必须开发同样的东西,但它可以识别阿拉伯字符。我可以获取您的代码并尝试修改它以识别阿拉伯语吗?我尝试了tesseract,但文件ara.traineddata不太好,我没有得到我想要的结果。你能帮我吗?是的,我想了很多,但我使用的是
maven
,所以即使我指向
.jar
文件的目录,也会出现同样的错误。@nguyenq hi nguyen!我非常喜欢你的产品Vietor使用tesseract。我必须开发同样的东西,但它可以识别阿拉伯字符。我可以获取您的代码并尝试修改它以识别阿拉伯语吗?我尝试了tesseract,但文件ara.traineddata不太好,我没有得到我想要的结果。你能帮我吗?