Tess4J: “Invalid calling convention 63” despite correct versions

北战南征 提交于 2019-12-23 09:51:19

问题


I try to do OCR and output as PDF using Tess4J and the following code on Linux (Ubuntu 16 Xenial).

public void testOcr() throws Exception {
    File imageFile = new File("/projects/de.conradt.core/tessdata/urkunde.jpg");
    ITesseract instance = new Tesseract1();  // tried both Tesseract() and Tesseract1()

    // File tessDataFolder = LoadLibs.extractTessResources("tessdata"); // Maven build bundles English data
    // instance.setDatapath(tessDataFolder.getParent());
    instance.setDatapath("/projects/de.conradt.core/tessdata");
    instance.setLanguage("deu");

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

    List<ITesseract.RenderedFormat> list = new ArrayList<ITesseract.RenderedFormat>();
    list.add(ITesseract.RenderedFormat.PDF);
    File pdfFile = new File("/projects/de.conradt.core/tessdata/urkunde.pdf");
    instance.createDocuments(pdfFile.getAbsolutePath(), "/projects/de.conradt.core/tessdata/urkunde", list);
}

The last line

        instance.createDocuments(pdfFile.getAbsolutePath(), "/projects/de.conradt.core/tessdata/urkunde", list);

throws an Exception:

11:03:12.651 [http-nio-8080-exec-1] ERROR net.sourceforge.tess4j.Tesseract - Invalid calling convention 63                                
java.lang.IllegalArgumentException: Invalid calling convention 63                                                                         
        at com.sun.jna.Native.createNativeCallback(Native Method)                                                                         
        at com.sun.jna.CallbackReference.<init>(CallbackReference.java:239)                                                               
        at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:413)                                                   
        at com.sun.jna.CallbackReference.getFunctionPointer(CallbackReference.java:395)                                                   
        at com.sun.jna.Function.convertArgument(Function.java:541)                                                                        
        at com.sun.jna.Function.invoke(Function.java:305)                                                                                 
        at com.sun.jna.Library$Handler.invoke(Library.java:236)                                                                           
        at com.sun.proxy.$Proxy89.gsapi_set_stdio(Unknown Source)                                                                         
        at org.ghost4j.Ghostscript.initialize(Ghostscript.java:323)                                                                       
        at net.sourceforge.tess4j.util.PdfUtilities.convertPdf2Png(PdfUtilities.java:103)                                                 
        at net.sourceforge.tess4j.util.PdfUtilities.convertPdf2Tiff(PdfUtilities.java:48)                                                 
        at net.sourceforge.tess4j.Tesseract.createDocuments(Tesseract.java:535)                                                           
        at net.sourceforge.tess4j.Tesseract.createDocuments(Tesseract.java:507)                                                           
        at de.conradt.core.Example.testOcr(Example.java:62)                                                                               
        at de.conradt.core.Example.ocr(Example.java:35)  

I found this to be a known (but supposedly closed) issue with Tess4J:

  • https://github.com/nguyenq/tess4j/issues/35
  • https://sourceforge.net/p/tess4j/discussion/1202294/thread/2a25344c/
  • https://github.com/zippy1978/ghost4j/issues/44

but I checked my versions as well as the TESSDATA_PREFIX env variable. It's all set correctly as far as I can see.

Tesseract and Leptonica version:

$ /usr/bin/tesseract --version                                                                        
tesseract 3.04.01                                                                                                                        
 leptonica-1.73                                                                                                                          
  libgif 5.1.2 : libjpeg 8d (libjpeg-turbo 1.4.2) : libpng 1.2.54 : libtiff 4.0.6 : zlib 1.2.8 : libwebp 0.4.4 : libopenjp2 2.1.0

Ghostscript version: (this is the latest version I get via apt-get)

$ ghostscript -v                                                                                      
GPL Ghostscript 9.18 (2015-10-05)                                                                                                        
Copyright (C) 2015 Artifex Software, Inc.  All rights reserved.  

Tess4j version:

3.2.1

and the TESSDATA_PREFIX (the config files etc. are under /projects/de.conradt.core/tessdata):

$ echo $TESSDATA_PREFIX                                                                                     
/projects/de.conradt.core

Looking at the Release log of Tess4j: http://tess4j.sourceforge.net/changelog.html, I should be using the correct version stack. Especially version 3.2 in the change log says:

Version 3.2 - 15 May 2016: Revert JNA to 4.1.0 due to "Invalid calling convention 63" errors invoking GhostScript via Ghost4J on Linux

so I thought I should be safe with 3.2.1.

Do I need to manually set anything about JNA? From my understanding, this had been fixed in 3.2.0 for Linux explicitly.


回答1:


Ok, I didn't explicitly reference JNA anywhere in my project pom, I thought this is all done in Tess4J 3.2.1 and its pom.xml. I added JNA 4.1.0 as a dependency in my own pom.xml now as well and this seems to solve the problem.

    <dependency>
        <groupId>net.java.dev.jna</groupId>
        <artifactId>jna</artifactId>
        <version>4.1.0</version>
    </dependency>


来源:https://stackoverflow.com/questions/40361873/tess4j-invalid-calling-convention-63-despite-correct-versions

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!