java.lang.UnsatisfiedLinkError 在 Java 中使用 TESSERACT API 时出现异常

java.lang.UnsatisfiedLinkError exception when using TESSERACT API in Java

我正在尝试为 Tesseract OCR 使用 Java JNA 包装器 API 但我一直收到 java.lang.UnsatisfiedLinkError 异常

我从http://sourceforge.net/projects/tess4j/

下载了最新版本

我确定我使用的是 32 位 JVM。以下是异常跟踪。

Exception in thread "main" java.lang.UnsatisfiedLinkError: The specified module could not be found.

at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:79)
at net.sourceforge.tess4j.TessAPI.(TessAPI.java:40)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:360)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:273)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:205)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:189)
at net.sourceforge.tess4j.Main.main(Main.java:12)

我有什么明显的错误吗?

我使用了 http://tess4j.sourceforge.net/codesample.html

中的示例代码
package net.sourceforge.tess4j.example;

import java.io.File;
import net.sourceforge.tess4j.*;

public class TesseractExample {

    public static void main(String[] args) {
        File imageFile = new File("eurotext.tif");
        Tesseract instance = Tesseract.getInstance();  // JNA Interface Mapping
        // Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping

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

我添加了一个 VM 参数,例如 jna.library.path=${pathtodll2},如果我使用该参数,则会出现以下错误,

Error: Could not find or load main class jna.library.path=D:\OCR\Tess4J\lib\win32-x86

我使用的是 Test4J 项目的最新版本, 2.0 版(2015 年 3 月 29 日)

我 运行 它在 Windows 7、32 位机器上。 Java7.

当我尝试使用进程资源管理器时,我无法看到正在加载的 dll,但我不确定,因为会立即抛出异常。

我更新到 Visual C++ Redistributable Packages for Visual Studio 2013

解决了这个问题

Visual C++ Redistributable for VS2012 还不够。

这个工具:http://www.dependencywalker.com/ 帮我找到了问题。

Visual C++ Redistributable Packages for Visual Studio 2013 是您需要在计算机上安装的软件包 :).

它肯定会工作 4....

UnsatisfiedLinkError 的解决方案:

  1. 安装 Visual C++ 2015 Redistributable Packages.

  2. 尝试将 tess4j 文件夹从本地移动到发生异常的系统。