Search code examples
javaapiocrtesseractjna

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


I'm trying to use the Java JNA wrapper for Tesseract OCR API but I keep getting java.lang.UnsatisfiedLinkError exception

I downloaded the latest version from http://sourceforge.net/projects/tess4j/

I made sure that I use a 32 bit JVM. Following is the exception trace.

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)

Any obvious mistakes that I'm doing?

I used the sample code from 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());
        }
    }}

I added a VM argument such as jna.library.path=${pathtodll2} and get the below error if I use the argument,

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

I'm using the latest version from the Test4J project, Version 2.0 (29 March 2015)

  • Upgrade to Tesseract 3.03 (r1050), which is compatible with Tesseract 3.03RC on Linux
  • Refactor Tesseract class for extensibility and thread-safety
  • Update English language data for Tesseract 3.02

I'm running it on Windows 7, 32 bit machine. Java 7.

When I try using the process Explorer I'm not able to see the dlls getting loaded but I'm not sure since the exception is thrown right away.


Solution

  • I resolved this problem by updating to Visual C++ Redistributable Packages for Visual Studio 2013

    Visual C++ Redistributable for VS2012 is not enough.

    This tool: http://www.dependencywalker.com/ helped me a lot to found the problem.