经过 2 天的谷歌搜索,我仍然无法找到 Tess4j 3.0 版问题的解决方案:java.lang.UnsatisfiedLinkError: 找不到指定的模块。
我在 Windows 10 x64 上编写服务器端 Spring boot 应用程序。我使用了这个教程http://tess4j.sourceforge.net/tutorial/ 我在 tess4j 项目的源代码中进行了 ant test ,并且该命令在我的电脑上运行正常。我还安装了 Visual C++ Redistributable for VS2012 和 Visual C++ Redistributable for VS2013。 但我的电脑中缺少 dll,libtesseract304.dll 依赖于:
这可能是问题的原因吗?但是 Tess4J-3.0-src 项目怎么可能在我的电脑上正常工作呢?
我的完整堆栈跟踪:
java.lang.UnsatisfiedLinkError: The specified module could not be found.
at com.sun.jna.Native.open(Native Method) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:263) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:403) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Library$Handler.<init>(Library.java:147) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:502) ~[jna.jar:4.2.1 (b0)]
at com.sun.jna.Native.loadLibrary(Native.java:481) ~[jna.jar:4.2.1 (b0)]
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.init(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source) ~[tess4j-3.0.jar:na]
at ocr.OCRController.handleFileUpload(OCRController.java:109) ~[classes/:na]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_51]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_51]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_51]
at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_51]
我的代码:
ITesseract instance = new Tesseract(); // JNA Interface Mapping
instance.setDatapath(new File(datapath).getPath());
instance.setLanguage("eng");
try {
String result = instance.doOCR(imageFile); //error here
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
行家:
<dependency>
<groupId>jai_imageio</groupId>
<artifactId>com.jai_imageio</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jai_imageio.jar</systemPath>
</dependency>
<dependency>
<groupId>commons-io-2.4</groupId>
<artifactId>com.commons-io-2.4</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/commons-io-2.4.jar</systemPath>
</dependency>
<dependency>
<groupId>jna</groupId>
<artifactId>com.jna</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/jna.jar</systemPath>
</dependency>
<dependency>
<groupId>tess4j-3.0</groupId>
<artifactId>com.tess4j-3.0</artifactId>
<version>3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/lib/tess4j-3.0.jar</systemPath>
</dependency>
我还尝试以强制方式加载库:
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/gsdll64");
Runtime.getRuntime().loadLibrary("lib/win32-x86-64/libtesseract304");
但没有成功:
There was an unexpected error (type=Internal Server Error, status=500).
C:\Users\Iuliia\IdeaProjects\ENumbersBackend\lib\win32-x86-64\libtesseract304.dll: Can't find dependent libraries
感谢您的帮助!
最佳答案
我认为您被depends.exe 的输出误导了。
该 DLL 仅导入这些其他 dll:
dumpbin libtesseract304.dll /imports|find ".dll"
Dump of file libtesseract304.dll
WS2_32.dll
liblept171.dll
MSVCP120.dll
MSVCR120.dll
KERNEL32.dll
要仔细检查,您可以获得用于编译该 dll 的链接器版本:
dumpbin libtesseract304.dll /headers | find "linker version"
12.00 linker version
因此,您所需要的只是 Visual Studio 2013 运行时(再次强调:不要被误导:12.0 是 2013,这可能会相当令人困惑)
大概是缺少了 liblept171.dll,因此您应该检查它的存储位置以及为什么一个项目能够找到它而另一个项目却找不到它。一个好主意是将所有依赖项复制到一个公共(public)路径中并将 java.library.path 设置为该目录(仅用于测试目的)
liblept171.dll
是 lept4j 的一部分,您的 lib 目录中有一个相应命名的 .jar,其中包含该 dll:
7z l lib\lept4j-1.0.1.jar | find ".dll"
2015-11-14 11:46:04 ..... 2406400 2406400 win32-x86-64\liblept171.dll
2015-11-14 11:46:04 ..... 1834496 1834496 win32-x86\liblept171.dll
此外,您应该注意 JRE、Visual Studio 运行时和 Tesseract 的位数是否匹配。如果有疑问:安装 x86 和 x64。
作为进一步的故障排除帮助,您可能想找出在哪里搜索 dll。将 procmon.exe 与该 dll 的过滤器一起使用。
关于java - Windows 中的 Tess4j 问题 : java. lang.UnsatisfiedLinkError : The specified module could not be found in instance. doOCR(imageFile),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34638689/