gpt4 book ai didi

java - Tess4J 非法状态异常 : Input not set

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:05:52 25 4
gpt4 key购买 nike

所以我已经设置了我的 Eclipse 和必要的库来让 Tess4J 工作,但是,当我使用提供的示例代码时它给我一个错误。图像文件就在工作区的根目录中,我什至尝试移动它甚至编辑方法以直接指向路径。都无济于事。老实说,我有点难过,想知道是否有人知道我需要查看的位置。

import java.io.File;
import net.sourceforge.tess4j.*;

public class Main {

public static void main(String[] args) {
File imageFile = new File("eurotext.tif");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping

try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}

我得到的错误如下:

Feb 11, 2014 11:05:13 AM net.sourceforge.tess4j.Tesseract doOCR
SEVERE: Input not set!
java.lang.IllegalStateException: Input not set!
at com.sun.media.imageioimpl.plugins.tiff.TIFFImageReader.getNumImages(TIFFImageReader.java:268)
at net.sourceforge.vietocr.ImageIOHelper.getIIOImageList(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at Main.main(Main.java:12)

java.lang.IllegalStateException: Input not set!

提前致谢!

编辑:快速更新,因为我一直在尝试找出很多东西并尝试多种东西。首先,我发现未设置输入是由错误放置的 .dll 文件引起的。但是,现在我遇到了一个新的更困难的错误。这是新代码(我只是添加了一个 println 来验证它是否能够在进入 try-catch 之前读取文件)。

import java.io.File;
import net.sourceforge.tess4j.*;

public class Main {

public static void main(String[] args) {
File imageFile = new File("C:\\Users\\Marouane Boutaib\\Java projects\\Tess4j\\eurotext.tif");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
System.out.println(imageFile.canRead());
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.UnsatisfiedLinkError: %1 is not a valid Win32 application.

at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source)
at net.sourceforge.tess4j.Tesseract.init(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
at Main.main(Main.java:12)

我和我的同事认为这是一个缺失的引用,但是,我已经按照指南进行了设置,并且我完全没有改变 Tess4J 开发人员自己提供的示例代码。最重要的是,我还没有在谷歌上找到另一个发生这种情况并得到解决的实例。

最佳答案

我知道已经太久了但是...

首先,请确保您使用的是 32 位 JVM。

其次,将所有dll(gsdll32.dll、liblept168.dll、libtesseract302.dll)插入某个文件夹,然后使用

System.setProperty("jna.library.path", "<the directory of the folder without a trailing slash>"). 

之后它就开始工作了。我也想到了...

关于java - Tess4J 非法状态异常 : Input not set,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21699052/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com