I am implementing an OCR system. When I placed dll files on the java class path it gives the following error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: G:\software\apache-tomcat-8.0.18-windows-x64\apache-tomcat-8.0.18\bin\win32-x86-64\libtesseract303.dll: Can't find dependent libraries
And after running the project if I check the java class path, all the dll files added are vanished. I followed almost all the tutorials related to tesseract
. But can't find a solution. Does anybody have an idea?
1).JDK version- 1.8(64 bit)
2).Library is 64 bit
3).all three libraries are placed within library path.
4) I followed the steps given by this tutorial
here.In this tutorial they have introduced the 32 bit libraries.Instead of that I used 64 bit libraries.I got the follwing error
java.lang.UnsatisfiedLinkError: Unable to load library 'libtesseract304': Native library (win32-x86-64/libtesseract303.dll) not found in resource path ([file:/C:/Users/User/Documents/GitHub/Linguist/build/web/WEB-INF/classes).
Then I tried to check if i can load the library using system.load(). Then I got the following error. My class path is placed with tomcat folder.
Exception in thread "main" java.lang.UnsatisfiedLinkError: G:\software\apache-tomcat-8.0.18-windows-x64\apache-tomcat-8.0.18\bin\win32-x86-64\libtesseract303.dll: Can't find dependent libraries
Find below a small working example application. From there you could start to investigate and pick the parts you need.
Assuming the following structure and files
pom.xml
sample.gif
src/main/java/sub/optimal/tess4j/Demo.java
tessdata/eng.traineddata
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>sub.optimal</groupId>
<artifactId>Tess4JDemo</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.shade.version>2.3</maven.shade.version>
</properties>
<dependencies>
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>3.0.0</version>
<type>jar</type>
</dependency>
<dependency>
<groupId>org.ghost4j</groupId>
<artifactId>ghost4j</artifactId>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>${maven.shade.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>sub.optimal.tess4j.Demo</mainClass>
</configuration>
</plugin>
</plugins>
</build>
</project>
sample.gif
src/main/java/sub/optimal/tess4j/Demo.java
package sub.optimal.tess4j;
import java.io.File;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
public class Demo {
public static void main(String[] args) {
File imageFile = new File("sample.gif");
Tesseract instance = new Tesseract();
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
e.printStackTrace(System.err);
}
}
}
tessdata/eng.traineddata
was downloaded from https://tesseract-ocr.googlecode.com/files/eng.traineddata.gz (don't forget to uncompress the file)
Running this small example with mvn exec:java
produce the following output
[INFO] --- exec-maven-plugin:1.4.0:java (default-cli) @ Tess4JDemo ---
Hello OCR!