所以我已经设置了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开发人员自己提供的示例代码。最重要的是,我还没有在Google上发现另一个已经发生并且已经解决的实例。
答案 0 :(得分:1)
我知道它太长了但是......
首先,确保使用32位JVM。
其次,将所有dll(gsdll32.dll,liblept168.dll,libtesseract302.dll)插入某个文件夹,然后使用
System.setProperty("jna.library.path", "<the directory of the folder without a trailing slash>").
之后它会起作用。我也发现了......