为什么tessdata会引发异常?

时间:2019-08-06 15:17:53

标签: tesseract tess4j

所有操作都在部署在Tomcat中的SpringBoot WAR文件的 MAC 上进行:

我已经安装了tesseract 4.1.0(通过Mac上的brew)。

对于Tessdata-Mac上的OCR

    <dependency>
        <groupId>net.sourceforge.tess4j</groupId>
        <artifactId>tess4j</artifactId>
        <version>4.4.0</version>
    </dependency>

我今天也将SpringBoot更新为:

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.6.RELEASE</version>
    <relativePath/> <!-- lookup parent from repository -->
</parent>

现在,当我尝试在tessdata(SpringBoot中的Service方法)中运行OCR逻辑时,我首先遇到此错误(在Mac上):

java.lang.NoSuchMethodError: com.sun.jna.Native.load(Ljava/lang/String;Ljava/lang/Class;)Lcom/sun/jna/Library;

然后,如果我再次尝试对西班牙png文件进行OCR,则会得到以下结果:

"Could not initialize class net.sourceforge.tess4j.TessAPI"

发生崩溃的Tessdata代码似乎是:

public String doOCR(BufferedImage var1) throws TesseractException {
    return this.doOCR((BufferedImage)var1, (Rectangle)null);

我已经在这里看到有关此问题的帖子,但是我看到的所有帖子都是针对Windows的。我还尝试为jna加载依赖项,以防万一,但这没什么区别。

有人遇到并解决了这个问题吗?

问题似乎出在tess4j 4.4.0上。如果我将其恢复为最新版本,则一切都会恢复。

真的很感谢一些想法。

1 个答案:

答案 0 :(得分:0)

似乎您的应用程序正在加载旧的JNA版本。 com.sun.jna.Native.load是JNA 5.x.x中的新增功能。因此,请确保您使用最新的JNA版本。

https://groups.google.com/forum/#!topic/jna-users/VKbCGUcotkg