Tesseract implementing a web service to trigger OC

2019-09-12 23:08发布

问题:

I am trying to implement a web service which triggers OCR actions of the server side.

Client code:

...
    sy = belgeArsivle(testServisIstegi, ab);
...    
      private static ServisYaniti belgeArsivle(com.ocr.ws.ServiceRequest serviceRequest,com.ocr.ws.Document document) {
            com.ocr.ws.ServiceRequest  service = new com.ocr.ws.OCRArsivWSService();
            com.ocr.ws.OCRArsivWS port = service.getOCRArsivWSPort();
            return port.docArchive(serviceRequest, document);
        }

When I run the code on the server side there is no problem. But whenever I call the web service method from the client I got this error code:

Exception: javax.xml.ws.soap.SOAPFaultException: Unable to load library 'libtesseract302': The specified module could not be found.

The working server-side code is:

public static void main(String[] args) {
        // TODO code application logic here

        File imageFile = new File("...OCR\\testTurWithBarcodeScanned.png");
        Tesseract instance = Tesseract.getInstance();
        try {
            String lang = "tur";
            instance.setLanguage(lang);

            String result = instance.doOCR(imageFile);
            System.out.println(result);

            // write in a file
            try {
                File file = new File("...MyOutputWithBarcode.txt");
                BufferedWriter out = new BufferedWriter(new FileWriter(file));
                out.write(result);
                out.close();
            } catch (IOException ex) {
            }

        } catch (TesseractException ep) {
            System.err.println(ep.getMessage());
        }

    }

I know that this error code is about Tesseract libraries. I put the corresponding .dll files (liblept168 and libtesseract302) under the client project's folder, added corresponding libraries (jna, jai_imageio, ghost4j_0.3.1), did neccessary changes in classpath but still getting this error.

I run a test code on the server side, it works fine. But the client side code is not working. Do I need to make some extra adjustment on the client side to run this web service?

回答1:

I found out that the actual problem was with the Tomcat Server. I had to put the jar files to the Tomcat's Sources under Properties, than voila!