简体   繁体   中英

Tesseract OCR not working in Web Project

I'm trying to use Tesseract OCR in a web application. The code runs fine when I run it as a JAVA application. But as soon as I put the same code in my web application, it doesn't work anymore. If put the function in the servlet, tomcat doesnt start at all. If I call it from a separate class by creating an object, On debugging I find that the object does not get created at all. I have included all the jars necessary.

Code in servlet

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

Inside other class

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());
}

Just some pointers I think you should check, in case if you are using Tess4j in Web Based Project:

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 above steps and try running again. Hope it works

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM