2016-04-25 84 views
0

我試圖在Web應用程序中使用Tesseract OCR。當我將它作爲JAVA應用程序運行時,代碼運行良好。但是,只要我將相同的代碼放入我的Web應用程序中,它就不再起作用了。如果把這個函數放在servlet中,tomcat根本不會啓動。如果我通過創建一個對象從一個單獨的類中調用它,在調試時,我發現該對象根本不會被創建。我已經包括了所有需要的罐子。Tesseract OCR不能在Web項目中工作

代碼中的servlet

OCRFullTrial ot = new OCRFullTrial(); 
ot.imgOCR(); 

內的其他類

public void imgOCR(){ 
    File imageFile = new File("D:\\OCRTesting\\0.jpg"); 

try { 
    ITesseract instance = new Tesseract(); //    
    System.out.println("1"); 

} catch (Exception e) { 
    System.err.println(e.getMessage()); 
} 

回答

0

只是一些指點,我認爲你應該檢查,在情況下,如果你正在使用Tess4j在基於Web的項目:

1) Put all your jars in WEB-INF > lib folder. 
2) The *.dll files that are provided along Tess4j must be in system32 folder (Windows). I don't know for other OS. 
3) Set the instance path using instance.setDataPath() method. It must point to folder containing tessdata folder. 
4) Set the language using instance.setLanguage() incase your tessdata has multiple languages training data in them. 

Crosscheck上面的步驟,並嘗試再次運行。希望它有效

+0

非常感謝!我遵循上述步驟,解決了這個問題。 –

+0

真棒..... :) – DarkHorse

+0

我也試圖獲得一個web服務在Apache服務器上託管。 我正在使用apache tika,並在API中說我只需要引用這個tesseract文件夾就像這樣TesseractOCRConfig config = new TesseractOCRConfig(); config.setTesseractPath(tesseractFolder); 如果我使用WEB-INF,應該如何啓動「/WEB-INF/tesseract/JarFileINeedToSpecifyPath.jar」,我應該在文件夾(tesseract jar文件?)中放置什麼以及應該使用什麼路徑? –