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.UnsatisfiedL
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!