获取UnsatisfiedLinkError:创建TessBaseAPI时java.library.path中没有jililept [英] Getting UnsatisfiedLinkError: no jnilept in java.library.path when I create TessBaseAPI
问题描述
我是java cpp和tesseract-ocr的新手.我几个小时都被困在一个问题上. 创建TessBaseAPI时出现 UnsatisfiedLinkError:java.library.path 中没有提示.下面是我的代码片段.
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 create TessBaseAPI. Below is the piece of my code.
public static void tesseractForPdf(String filePath) throws Exception {
BytePointer outText;
TessBaseAPI api = new TessBaseAPI();//getting the UnsatisfiedLinkError exception here.
// Initialize tesseract-ocr with English, without specifying tessdata path
if (api.Init(".", "ENG") != 0) {
System.err.println("Could not initialize tesseract.");
System.exit(1);
}
// Open input image with leptonica library
PIX image = pixRead(filePath);
api.SetImage(image);
// Get OCR result
outText = api.GetUTF8Text();
String string = outText.getString();
System.out.println("OCR output:\n" + string);
// Destroy used object and release memory
api.End();
outText.deallocate();
pixDestroy(image);
}
我正在使用TessBaseAPI api异常= new TessBaseAPI();线
Exception I am getting on TessBaseAPI api = new TessBaseAPI(); line
Exception in thread "main" java.lang.UnsatisfiedLinkError: no jnilept in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:702)
at org.bytedeco.javacpp.Loader.load(Loader.java:500)
at org.bytedeco.javacpp.Loader.load(Loader.java:417)
at org.bytedeco.javacpp.lept.<clinit>(lept.java:10)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at org.bytedeco.javacpp.Loader.load(Loader.java:472)
at org.bytedeco.javacpp.Loader.load(Loader.java:417)
at org.bytedeco.javacpp.tesseract$TessBaseAPI.<clinit>(tesseract.java:3648)
at om.practiceproblems.BasicTesseractExampleTest.givenTessBaseApi_whenImageOcrd_thenTextDisplayed(BasicTesseractExampleTest.java:35)
at com.practiceproblems.BasicTesseractExampleTest.main(BasicTesseractExampleTest.java:22)
Caused by: java.lang.UnsatisfiedLinkError: no liblept in java.library.path
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.bytedeco.javacpp.Loader.loadLibrary(Loader.java:702)
at org.bytedeco.javacpp.Loader.load(Loader.java:491)
... 9 more
在我的示例中,我将java-presets库tesseract-3.04.01-1.2和leptonica-1.73-1.2.jar与javacpp-1.2.1一起使用.
我确实看到了这个 https://github.com/bytedeco/javacpp-presets/issues/46 以及关于SO和github的一些讨论,指出此问题已在jacacpp-1.1本身中修复.但是我正在使用javacpp1.2.
对于解决此问题或找到根本原因的任何帮助,我将不胜感激.
I am using java-presets libraries tesseract-3.04.01-1.2 and leptonica-1.73-1.2.jar with javacpp-1.2.1 in my example.I have windows OS.
I did see this https://github.com/bytedeco/javacpp-presets/issues/46 and couple of discussions on SO and github which pointed that this issue is fixed in jacacpp-1.1 itself.But I am using javacpp1.2.
I would really appreciate any help in resolving the issue or finding the root cause.
推荐答案
您可以克隆或下载该项目:
you could clone or download the project:
https://github.com/bytedeco/javacpp-presets#the -cppbuildsh-scripts
然后构建模块:用于Tesseract的JavaCPP预设和用于Leptonica的JavaCPP预设;
then build the modules: JavaCPP Presets for Tesseract and JavaCPP Presets for Leptonica;
(要构建leptonica项目,您可能需要安装 nasm https://www.nasm.us/)
(to build the leptonica project you maybe need to install nasm https://www.nasm.us/)
(要构建整个javacpp-presets项目,您还必须安装cmake )
这将创建本机库:
libjnilept.so和libjnitesseract.so
libjnilept.so and libjnitesseract.so
然后您必须指定jni.library.path
then you have to specify the jni.library.path
您可以执行以下操作:
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);
(您可以在虚拟机选项上指定-Djava.library.path =)
您只需要放入生成的文件: libjnilept.so和libjnitesseract.so在某个文件夹中,并将此路径设置为:jni.library.path
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>
您也可以尝试添加
<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>
并在构建中添加一个maven-assembly-plugin
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:
由于Tesseract的语言环境要求,需要导出LC_ALL = C 在运行任何客户端程序之前.
Due to Tesseract's locale requirements, export LC_ALL=C is required before running any client programs.
如此:
<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>
来源:
- https://github.com/nguyenq/tess4j/issues/106
- https://github.com/sirfz/tesserocr/issues/165 >
source:
- https://github.com/nguyenq/tess4j/issues/106
- https://github.com/sirfz/tesserocr/issues/165
这篇关于获取UnsatisfiedLinkError:创建TessBaseAPI时java.library.path中没有jililept的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!