因此,我設置了我的Eclipse和必要的庫以使Tess4J正常工作,但是,當我使用提供的示例代碼時,它給了我一個錯誤。圖像文件就在工作區的根目錄中,我甚至試着移動它,甚至編輯方法直接指向路徑。一切都無濟於事。我有點難住,說實話,並想知道如果有人可能有一個想法,我需要尋找。Tess4J IllegalStateException:輸入未設置
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上發現過這種情況,並且已經得到解決。
看起來像是一個點滴問題。什麼是你的軟件配置? – nguyenq
虛擬機存在一個問題,我在設置64位時犯了一個小錯誤。現在它運行得很好,但是,我在API /準確性/等方面遇到了問題,但還沒有具體問題。感謝至少花時間看看它! –