2016-04-22 58 views
0

我剛開始嘗試寫一個簡單的java代碼來做一些簡單的OCR,使用代碼和建議找到here在Windows中使用tesseract的Java OCR程序

我已經安裝了庫,並且IDE(NetBeans)中的項目看起來就像我附加的圖片。

我得到這些錯誤:

10:47:30.099 [主] WARN net.sourceforge.tess4j.util.LoadLibs - 來源「C:\用戶\西蒙%20Bothner \文檔\的NetBeansProjects \ OCRTest \編譯\類\ Win32的x86-64' 的不存在

java.io.FileNotFoundException:源 「C:\用戶\西蒙%20Bothner \文檔\的NetBeansProjects \ OCRTest \建立\類\ Win32的x86的64'不存在

at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1074) 
at org.apache.commons.io.FileUtils.copyFile(FileUtils.java:1038) 
at net.sourceforge.tess4j.util.LoadLibs.copyResources(LoadLibs.java:138) 
at net.sourceforge.tess4j.util.LoadLibs.extractTessResources(LoadLibs.java:105) 
at net.sourceforge.tess4j.util.LoadLibs.<clinit>(LoadLibs.java:59) 
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:42) 
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:367) 
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:280) 
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212) 
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:196) 
at Main.main(Main.java:15) 

線程「main」java.lang.Uns中的異常atisfiedLinkError:找不到指定的模塊。

at com.sun.jna.Native.open(Native Method) 
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:263) 
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403) 
at com.sun.jna.Library$Handler.<init>(Library.java:147) 
at com.sun.jna.Native.loadLibrary(Native.java:502) 
at com.sun.jna.Native.loadLibrary(Native.java:481) 
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:77) 
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:42) 
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:367) 
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:280) 
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212) 
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:196) 
at Main.main(Main.java:15) 

C:\用戶\西蒙Bothner \應用程序數據\本地\的NetBeans \緩存\ 8.1 \執行人-片段\ run.xml:53:的Java返回:1 BUILD FAILED(總時間:0秒)

我試圖用this教程,但我似乎缺少一個.dll,在liblept168.dll ...

有人可以幫助我?我很新,並且似乎無法得到這個工作...

非常感謝! :)

+0

也許這個答案可能有助於找到問題:http://stackoverflow.com/questions/35547211/issue-with-the-libtesseract303-dll-in-netbeans#35553331 – SubOptimal

+0

Tess4J教程頁面包括NetBeans示例:http: //tess4j.sourceforge.net/tutorial/ – nguyenq

+0

檢查出答案後,會盡量讓它起作用,謝謝! :) 試過教程以下,但不能得到它的工作:/ – Simon

回答

0

第1步:http://tphangout.com/how-to-use-the-tesseract-api-to-perform-ocr-in-your-java-code/
打開上面的鏈接,看看如何在Java中正確安裝Tesseract。

第2步:閱讀它,如果你仍然得到「庫未打開」錯誤,下載Microsoft Visual Studio的> 12.0,並更新你的JDK版本後(我也得到了同樣的錯誤)。

第3步:

public class tesserct 
{ 
    public static void main(String[] args) 
    { 
     //System.setProperty("jna.library.path", "64".equals(System.getProperty("sun.arch.data.model")) ? "lib/win32-x86" : "lib/win32-x86-64"); 

     System.setProperty("jna.library.path", "32".equals(System.getProperty("sun.arch.data.model")) ? "lib/win32-x86" : "lib/win32-x86-64"); 

     File imageFile = new File("F:\\Wallpaper & photo\\wallpaper\\holi wollpepar\\happy-holi-2013-hd-wallpaper1.jpg"); 
     ITesseract instance = new Tesseract(); // JNA Interface Mapping 
     // ITesseract instance = new Tesseract1(); // JNA Direct Mapping 
     File tessDataFolder = LoadLibs.extractTessResources("tessdata"); // Maven build bundles English data 
     instance.setDatapath(tessDataFolder.getParent()); 

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

您的NetBeans運行上面的代碼,並嘗試它。