3

Hi I have a problem using tess4j library with java. I´m using maven.

Exception in thread "main" java.lang.UnsatisfiedLinkError: Can not find the specified module.

I´m sure that the file setted in the path exist because the method exist returns true. The debuger show the problem in this instruction :

String result = instance.doOCR(imageFile);

This is the error:

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.<init>(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.TessAPI.<clinit>(TessAPI.java:45)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:283)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:219)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:168)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:152)
at Index.main(Index.java:17)

My dependency

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

My code

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



public class Index {

public static void main(String[] args) {

File imageFile = new File("C:\\Users\\Juan\\workspace\\TESSERACT\\src\\main\\java\\img.png");
Tesseract instance = Tesseract.getInstance(); //

try {
System.out.println( imageFile.exists());

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

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

}

Thanks in advance.

Juan Camilo Mejia
  • 952
  • 3
  • 14
  • 28

3 Answers3

4

It seems that you didn't add libtesseract302.dll and liblept168.dll to the classpath. Using Maven only enables you to download the tess4j jar, you still need to add libtesseract302.dll and liblept168.dll to your classpath.

To get Tess4J to run in Eclipse: See Here Maven does step 1 and 2 for you, you still need to do step 3.

and also Here, it might help you.

Mel
  • 453
  • 1
  • 4
  • 14
  • Hi thanks for your answer. I already have those dll in the proyect, but in the next tip i tried to do the 3 step but the project doesn´t contains the file tessdll.dll – Juan Camilo Mejia Aug 04 '14 at 18:00
  • It depends if you are using 64bits or 32bits. tessdll.dll should be found at C:\Windows\SysWOW64 or C:\Windows\System32 – Mel Aug 04 '14 at 18:20
2

For the last version of tess4j - 3.0 - it is enough to add

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

instead all previously maven dependencies which have been needed for tess4j.

Yuliia Ashomok
  • 8,336
  • 2
  • 60
  • 69
1

It looks like you are missing native libraries used by tess4j. Download the dlls and run your program by setting the java.library.path appropriately

6ton
  • 4,174
  • 1
  • 22
  • 37