I am new to java cpp and tesseract-ocr. I am stuck with one issue from couple of hours. I am getting UnsatisfiedLinkError: no jnilept in java.library.path when I cre
you could clone or download the project:
https://github.com/bytedeco/javacpp-presets#the-cppbuildsh-scripts
then build the modules: JavaCPP Presets for Tesseract and JavaCPP Presets for Leptonica;
(to build the leptonica project you maybe need to install nasm https://www.nasm.us/)
(to build the entire javacpp-presets project you also have to install cmake)
that would create the native libraries:
libjnilept.so and libjnitesseract.so
then you have to specify the jni.library.path
You can do it with:
System.setProperty(JAVA_LIBRARY_PATH, tmpDirName);
/* Optionally add these two lines */
System.setProperty("jna.library.path", tmpDirName);
System.setProperty("jni.library.path", tmpDirName);
final Field fieldSysPath;
fieldSysPath = ClassLoader.class.getDeclaredField(SYS_PATHS);
fieldSysPath.setAccessible(true);
fieldSysPath.set(null, null);
(you could instead specify the -Djava.library.path= on the virtual machine options)
you only have to put the generated files: libjnilept.so and libjnitesseract.so in some folder and set this path for: jni.library.path
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>tesseract</artifactId>
<version>4.0.0-1.4.4</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>leptonica</artifactId>
<version>1.77.0-1.4.4</version>
</dependency>
you can also try to add
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>leptonica-platform</artifactId>
<version>1.77.0-1.4.4</version>
</dependency>
<dependency>
<groupId>org.bytedeco.javacpp-presets</groupId>
<artifactId>tesseract-platform</artifactId>
<version>4.0.0-1.4.4</version>
</dependency>
and add into the build a maven-assembly-plugin
<build>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<!-- new -->
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</build>
Also, you could also get an error like this:
sscanf(line, "%" QUOTED_TOKENSIZE "s %" QUOTED_TOKENSIZE "s %f %f",
linear_token, essential_token, &ParamDesc[i].Min, &ParamDesc[i].Max) == 4
:Error:Assert failed:in file clusttool.cpp, line 73
#
# A fatal error has been detected by the Java Runtime Environment:
Due to Tesseract's locale requirements, export LC_ALL=C is required before running any client programs.
so:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<environmentVariables>
<LC_ALL>C</LC_ALL>
</environmentVariables>
<executable>java</executable>
<arguments>
<argument>-classpath</argument>
<classpath />
<argument>${classpath}</argument>
</arguments>
</configuration>
</plugin>
source:
- https://github.com/nguyenq/tess4j/issues/106
- https://github.com/sirfz/tesserocr/issues/165