nguyenq / tess4j

Java JNA wrapper for Tesseract OCR API
Apache License 2.0
1.57k stars 371 forks source link

UnsatisfiedLinkError: The specified module could not be found #95

Closed nobleson closed 5 years ago

nobleson commented 6 years ago

I have gradually followed this document example, using netbeans. http://tess4j.sourceforge.net/tutorial/
My System configuration is as follow: Windows 7 64bit. JDK 1.8 Microsoft visual c++ 2015 86x already existed so i installed 2017 64bit also. I have also find and downloaded all the required jar files as you can see. commons-io-2.5.jar jai-imageio-core-1.3.1.jar jna-4.1.0.jar jul-to-slf4j-1.8.0-beta2.jar lept4j-1.10.0.jar logback-classic-1.1.3.jar logback-core-1.1.3.jar slf4j.jar tess4j-4.0.2.jar

I also added the testdata folder but i got this error

run: Exception in thread "main" java.lang.UnsatisfiedLinkError: The specified module could not be found.

at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
at com.sun.jna.Library$Handler.<init>(Library.java:147)
at com.sun.jna.Native.loadLibrary(Native.java:412)
at com.sun.jna.Native.loadLibrary(Native.java:391)
at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:84)
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:42)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:364)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:277)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:209)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:193)
at tess4j.example.TesseractExample.main(TesseractExample.java:27)

Please i need help.

nguyenq commented 6 years ago

Use lept4j-1.9.4 as tess4j-4.0.2 is currently linked against.

nobleson commented 6 years ago

I have removed lept4j-1.10.0.jar and then added lept4j-1.9.4. I then Clean and Build The project, but i am getting the same error: From the tutorial> Tesseract and Leptonica Windows 32- and 64-bit DLLs are embedded in tess4j.jar and lept4j.jar, respectively. They will automatically be extracted and loaded at run-time.

Therefore i was also expecting the system to extract the DLL files and load them in my dist folder, something like that, when i Clean and Build the project. In OpenCV, one need to point to the DLL files in the VM Option in Netbeaans: -Djava.library.path="C:\Users\Luke\Documents\lib\opencv" Why i am thinking this way is the UnsatisfiedLinkError, which is common to JNI problem.

nguyenq commented 6 years ago

Please check to see if the DLLs (libtesseract400.dll and liblept1753.dll) were extracted to C:\Users\<yourusername>\AppData\Local\Temp\tess4j folder. You may want to empty the folder before trying it again.

nobleson commented 6 years ago

Yes i found the DLL files in this directory> C:\Users\Luke\AppData\Local\Temp\tess4j\win32-x86-64 There are many of them, including the ones you mentioned. I now deleted the win32-x86-64 folder and i did Clean Build and Run but i got the same error, even though the DLL files are extracted to that location. Only the DLL files (libtesseract400.dll and liblept1753.dll) are there now.

nguyenq commented 6 years ago

OK, now try with either Microsoft Visual VC++ 2015 or 2017 64-bit redistributable.

nobleson commented 6 years ago

Sir, I have added both Microsoft Visual VC++ 2015 64-bit and 2017 64-bit redistributables and clean and build still the error remains. Sample code i am running File imageFile = new File("eurotext.jpg"); ITesseract instance = new Tesseract(); // JNA Interface Mapping try { String result = instance.doOCR(imageFile); System.out.println(result); } catch (TesseractException e) { System.err.println(e.getMessage()); }

nobleson commented 6 years ago

I have also linked the temp folder to my project under VM options and now th error is this: Exception in thread "main" java.lang.UnsatisfiedLinkError: The specified module could not be found.

at com.sun.jna.Native.open(Native Method)
at com.sun.jna.Native.open(Native.java:1759)
nguyenq commented 6 years ago

UnsatisfiedLinkError is a result of the application unable to find the required native libraries to load. Can you use Dependency Walker tool to determine what native resource is missing?

andrebienemann commented 6 years ago

Starting from Tess4J 4.0.0, I've exactly the same problem on my Windows 10.

nguyenq commented 6 years ago

Beginning Tess4J 4.0.0, the DLL was built using VS2017. I may have to drop back to VS1015. And this is applicable to Lept4J also. If anyone is willing to help test, I can push a 4.0.3-SNAPSHOT to Maven.

andrebienemann commented 6 years ago

Yes, it'd be nice!

nguyenq commented 6 years ago

It looks like the .vcxproj are the same, so I'm not sure changing Visual Studio will make a difference. Did you try Dependency Walker? What are the results of executing unit tests on current Lept4J (1.9.4) and Tess4J (4.0.2) code? Tess4J has direct dependency on Lept4J, so if the latter failed to load, it would cause the same exception. We want to narrow down our investigation cope as much as possible.

hampelratte commented 6 years ago

I'm having the same problem. On the system the Microsoft Visual C++ 2015 Redistributable exist as 32 and 64 bit version. I'm using the 4.0.3-SNAPSHOT. The dll files are correctly extracted to the temp folder. I tried dependency walker and it prints out these messages:

Error: At least one required implicit or forwarded dependency was not found.
Error: At least one module has an unresolved import due to a missing export function in an implicitly dependent module.
Error: A circular dependency was detected.
Warning: At least one delay-load dependency module was not found.
Warning: At least one module has an unresolved import due to a missing export function in a delay-load dependent module.

And the following DLLs can't be found on the system. And from there I don't know how to debug further. I'm also not sure, if this information is relevant, because I don't know how to use dependency walker. Any ideas?

API-MS-WIN-CORE-APIQUERY-L1-1-0.DLL
API-MS-WIN-CORE-APPCOMPAT-L1-1-0.DLL
API-MS-WIN-CORE-APPCOMPAT-L1-1-1.DLL
API-MS-WIN-CORE-APPINIT-L1-1-0.DLL
API-MS-WIN-CORE-ATOMS-L1-1-0.DLL
API-MS-WIN-CORE-COMM-L1-1-0.DLL
API-MS-WIN-CORE-CONSOLE-L1-2-0.DLL
API-MS-WIN-CORE-CONSOLE-L2-1-0.DLL
API-MS-WIN-CORE-CONSOLE-L2-2-0.DLL
API-MS-WIN-CORE-CONSOLE-L3-2-0.DLL
API-MS-WIN-CORE-CRT-L1-1-0.DLL
API-MS-WIN-CORE-CRT-L2-1-0.DLL
API-MS-WIN-CORE-DATETIME-L1-1-1.DLL
API-MS-WIN-CORE-DATETIME-L1-1-2.DLL
API-MS-WIN-CORE-DEBUG-L1-1-1.DLL
API-MS-WIN-CORE-DELAYLOAD-L1-1-0.DLL
API-MS-WIN-CORE-DELAYLOAD-L1-1-1.DLL
API-MS-WIN-CORE-ERRORHANDLING-L1-1-2.DLL
API-MS-WIN-CORE-ERRORHANDLING-L1-1-3.DLL
API-MS-WIN-CORE-FIBERS-L1-1-0.DLL
API-MS-WIN-CORE-FIBERS-L2-1-0.DLL
API-MS-WIN-CORE-FIBERS-L2-1-1.DLL
API-MS-WIN-CORE-FILE-L1-2-1.DLL
API-MS-WIN-CORE-FILE-L1-2-2.DLL
API-MS-WIN-CORE-FILE-L2-1-1.DLL
API-MS-WIN-CORE-FILE-L2-1-2.DLL
API-MS-WIN-CORE-FILE-L2-1-3.DLL
API-MS-WIN-CORE-HEAP-L2-1-0.DLL
API-MS-WIN-CORE-HEAP-OBSOLETE-L1-1-0.DLL
API-MS-WIN-CORE-IO-L1-1-0.DLL
API-MS-WIN-CORE-IO-L1-1-1.DLL
API-MS-WIN-CORE-JOB-L1-1-0.DLL
API-MS-WIN-CORE-KERNEL32-LEGACY-L1-1-0.DLL
API-MS-WIN-CORE-KERNEL32-PRIVATE-L1-1-0.DLL
API-MS-WIN-CORE-LARGEINTEGER-L1-1-0.DLL
API-MS-WIN-CORE-LIBRARYLOADER-L1-2-0.DLL
API-MS-WIN-CORE-LIBRARYLOADER-L1-2-1.DLL
API-MS-WIN-CORE-LIBRARYLOADER-L1-2-2.DLL
API-MS-WIN-CORE-LIBRARYLOADER-L2-1-0.DLL
API-MS-WIN-CORE-LOCALIZATION-L2-1-0.DLL
API-MS-WIN-CORE-LOCALIZATION-OBSOLETE-L1-2-0.DLL
API-MS-WIN-CORE-LOCALIZATION-PRIVATE-L1-1-0.DLL
API-MS-WIN-CORE-MEMORY-L1-1-1.DLL
API-MS-WIN-CORE-MEMORY-L1-1-2.DLL
API-MS-WIN-CORE-MEMORY-L1-1-3.DLL
API-MS-WIN-CORE-MISC-L1-1-0.DLL
API-MS-WIN-CORE-NAMEDPIPE-L1-2-1.DLL
API-MS-WIN-CORE-NAMEDPIPE-L1-2-2.DLL
API-MS-WIN-CORE-NAMESPACE-L1-1-0.DLL
API-MS-WIN-CORE-NORMALIZATION-L1-1-0.DLL
API-MS-WIN-CORE-PERFCOUNTERS-L1-1-0.DLL
API-MS-WIN-CORE-PRIVATEPROFILE-L1-1-0.DLL
API-MS-WIN-CORE-PROCESSENVIRONMENT-L1-2-0.DLL
API-MS-WIN-CORE-PROCESSSNAPSHOT-L1-1-0.DLL
API-MS-WIN-CORE-PROCESSTHREADS-L1-1-2.DLL
API-MS-WIN-CORE-PROCESSTHREADS-L1-1-3.DLL
API-MS-WIN-CORE-PROCESSTOPOLOGY-L1-1-0.DLL
API-MS-WIN-CORE-PSAPI-ANSI-L1-1-0.DLL
API-MS-WIN-CORE-PSAPI-L1-1-0.DLL
API-MS-WIN-CORE-REALTIME-L1-1-0.DLL
API-MS-WIN-CORE-REGISTRY-L1-1-0.DLL
API-MS-WIN-CORE-REGISTRY-L1-1-1.DLL
API-MS-WIN-CORE-REGISTRY-L1-1-2.DLL
API-MS-WIN-CORE-SIDEBYSIDE-L1-1-0.DLL
API-MS-WIN-CORE-STRING-L2-1-0.DLL
API-MS-WIN-CORE-STRING-OBSOLETE-L1-1-0.DLL
API-MS-WIN-CORE-STRINGANSI-L1-1-0.DLL
API-MS-WIN-CORE-SYNCH-L1-2-1.DLL
API-MS-WIN-CORE-SYSINFO-L1-2-0.DLL
API-MS-WIN-CORE-SYSINFO-L1-2-1.DLL
API-MS-WIN-CORE-SYSINFO-L1-2-3.DLL
API-MS-WIN-CORE-SYSTEMTOPOLOGY-L1-1-0.DLL
API-MS-WIN-CORE-SYSTEMTOPOLOGY-L1-1-1.DLL
API-MS-WIN-CORE-THREADPOOL-L1-2-0.DLL
API-MS-WIN-CORE-THREADPOOL-LEGACY-L1-1-0.DLL
API-MS-WIN-CORE-THREADPOOL-PRIVATE-L1-1-0.DLL
API-MS-WIN-CORE-WINDOWSERRORREPORTING-L1-1-0.DLL
API-MS-WIN-CORE-WINDOWSERRORREPORTING-L1-1-1.DLL
API-MS-WIN-CORE-WINDOWSERRORREPORTING-L1-1-2.DLL
API-MS-WIN-CORE-WOW64-L1-1-0.DLL
API-MS-WIN-CORE-WOW64-L1-1-1.DLL
API-MS-WIN-CORE-XSTATE-L2-1-0.DLL
API-MS-WIN-EVENTING-CONSUMER-L1-1-0.DLL
API-MS-WIN-EVENTING-CONSUMER-L1-1-1.DLL
API-MS-WIN-EVENTING-CONTROLLER-L1-1-0.DLL
API-MS-WIN-EVENTING-PROVIDER-L1-1-0.DLL
API-MS-WIN-GDI-INTERNAL-UAP-L1-1-0.DLL
API-MS-WIN-SECURITY-APPCONTAINER-L1-1-0.DLL
API-MS-WIN-SECURITY-AUDIT-L1-1-0.DLL
API-MS-WIN-SECURITY-AUDIT-L1-1-1.DLL
API-MS-WIN-SECURITY-BASE-L1-1-0.DLL
API-MS-WIN-SECURITY-BASE-L1-2-0.DLL
API-MS-WIN-SECURITY-BASE-PRIVATE-L1-1-0.DLL
API-MS-WIN-SERVICE-CORE-L1-1-0.DLL
API-MS-WIN-SERVICE-CORE-L1-1-1.DLL
API-MS-WIN-SERVICE-CORE-L1-1-2.DLL
API-MS-WIN-SERVICE-MANAGEMENT-L1-1-0.DLL
API-MS-WIN-SERVICE-MANAGEMENT-L2-1-0.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-0.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-2.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-3.DLL
API-MS-WIN-SERVICE-PRIVATE-L1-1-4.DLL
API-MS-WIN-SERVICE-WINSVC-L1-1-0.DLL
API-MS-WIN-APPMODEL-RUNTIME-INTERNAL-L1-1-2.DLL
API-MS-WIN-APPMODEL-RUNTIME-L1-1-1.DLL
API-MS-WIN-CORE-COM-L1-1-0.DLL
API-MS-WIN-CORE-LOCALIZATION-L1-1-0.DLL
API-MS-WIN-CORE-LOCALREGISTRY-L1-1-0.DLL
API-MS-WIN-CORE-REGISTRY-L2-1-0.DLL
API-MS-WIN-CORE-REGISTRY-PRIVATE-L1-1-0.DLL
API-MS-WIN-CORE-VERSION-L1-1-0.DLL
API-MS-WIN-CORE-VERSION-PRIVATE-L1-1-0.DLL
API-MS-WIN-DEVICES-CONFIG-L1-1-1.DLL
API-MS-WIN-DEVICES-QUERY-L1-1-0.DLL
API-MS-WIN-EVENTING-CLASSICPROVIDER-L1-1-0.DLL
API-MS-WIN-EVENTING-OBSOLETE-L1-1-0.DLL
API-MS-WIN-POWER-BASE-L1-1-0.DLL
API-MS-WIN-POWER-SETTING-L1-1-0.DLL
API-MS-WIN-SECURITY-CREDENTIALS-L1-1-0.DLL
API-MS-WIN-SECURITY-CREDENTIALS-L2-1-0.DLL
API-MS-WIN-SECURITY-GROUPPOLICY-L1-1-0.DLL
API-MS-WIN-SECURITY-LSALOOKUP-L1-1-0.DLL
API-MS-WIN-SECURITY-LSALOOKUP-L2-1-0.DLL
API-MS-WIN-SECURITY-LSAPOLICY-L1-1-0.DLL
API-MS-WIN-SECURITY-PROVIDER-L1-1-0.DLL
API-MS-WIN-SECURITY-SDDL-L1-1-0.DLL
API-MS-WIN-STATESEPARATION-HELPERS-L1-1-0.DLL
EXT-MS-ONECORE-APPMODEL-STATEREPOSITORY-INTERNAL-L1-1-1.DLL
EXT-MS-WIN-ADVAPI32-NPUSERNAME-L1-1-0.DLL
EXT-MS-WIN-ADVAPI32-NTMARTA-L1-1-0.DLL
EXT-MS-WIN-ADVAPI32-REGISTRY-L1-1-0.DLL
EXT-MS-WIN-ADVAPI32-REGISTRY-L1-1-1.DLL
EXT-MS-WIN-ADVAPI32-SAFER-L1-1-0.DLL
EXT-MS-WIN-APPMODEL-APPEXECUTIONALIAS-L1-1-0.DLL
EXT-MS-WIN-APPMODEL-APPEXECUTIONALIAS-L1-1-1.DLL
EXT-MS-WIN-APPMODEL-DAXCORE-L1-1-0.DLL
EXT-MS-WIN-APPXDEPLOYMENTCLIENT-APPXDEPLOY-L1-1-0.DLL
EXT-MS-WIN-APPXDEPLOYMENTCLIENT-APPXDEPLOYONECORE-L1-1-0.DLL
EXT-MS-WIN-AUTHZ-CONTEXT-L1-1-0.DLL
EXT-MS-WIN-CORE-WINRT-REMOTE-L1-1-0.DLL
EXT-MS-WIN-EDPUTIL-POLICY-L1-1-0.DLL
EXT-MS-WIN-EVENTING-RUNDOWN-L1-1-0.DLL
EXT-MS-WIN-FECLIENT-ENCRYPTEDFILE-L1-1-0.DLL
EXT-MS-WIN-GDI-CLIPPING-L1-1-0.DLL
EXT-MS-WIN-GDI-DC-CREATE-L1-1-0.DLL
EXT-MS-WIN-GDI-DC-L1-2-0.DLL
EXT-MS-WIN-GDI-DC-L1-2-1.DLL
EXT-MS-WIN-GDI-DRAW-L1-1-0.DLL
EXT-MS-WIN-GDI-DRAW-L1-1-1.DLL
EXT-MS-WIN-GDI-DRAW-L1-1-2.DLL
EXT-MS-WIN-GDI-DRAW-L1-1-3.DLL
EXT-MS-WIN-GDI-FONT-L1-1-0.DLL
EXT-MS-WIN-GDI-FONT-L1-1-1.DLL
EXT-MS-WIN-GDI-FONT-L1-1-2.DLL
EXT-MS-WIN-GDI-FONT-L1-1-3.DLL
EXT-MS-WIN-GDI-INTERNAL-DESKTOP-L1-1-0.DLL
EXT-MS-WIN-GDI-INTERNAL-DESKTOP-L1-1-1.DLL
EXT-MS-WIN-GDI-INTERNAL-DESKTOP-L1-1-2.DLL
EXT-MS-WIN-GDI-METAFILE-L1-1-0.DLL
EXT-MS-WIN-GDI-METAFILE-L1-1-1.DLL
EXT-MS-WIN-GDI-METAFILE-L1-1-2.DLL
EXT-MS-WIN-GDI-PATH-L1-1-0.DLL
EXT-MS-WIN-GDI-PRINT-L1-1-0.DLL
EXT-MS-WIN-GDI-PRIVATE-L1-1-0.DLL
EXT-MS-WIN-GDI-WCS-L1-1-0.DLL
EXT-MS-WIN-GPAPI-GROUPPOLICY-L1-1-0.DLL
EXT-MS-WIN-KERNEL32-APPCOMPAT-L1-1-0.DLL
EXT-MS-WIN-KERNEL32-DATETIME-L1-1-0.DLL
EXT-MS-WIN-KERNEL32-ERRORHANDLING-L1-1-0.DLL
EXT-MS-WIN-KERNEL32-FILE-L1-1-0.DLL
EXT-MS-WIN-KERNEL32-QUIRKS-L1-1-0.DLL
EXT-MS-WIN-KERNEL32-QUIRKS-L1-1-1.DLL
EXT-MS-WIN-KERNEL32-REGISTRY-L1-1-0.DLL
EXT-MS-WIN-KERNEL32-SIDEBYSIDE-L1-1-0.DLL
EXT-MS-WIN-KERNELBASE-PROCESSTHREAD-L1-1-0.DLL
EXT-MS-WIN-MRMCORER-RESMANAGER-L1-1-0.DLL
EXT-MS-WIN-NETWORKING-WCMAPI-L1-1-0.DLL
EXT-MS-WIN-NTDSAPI-ACTIVEDIRECTORYCLIENT-L1-1-0.DLL
EXT-MS-WIN-NTDSAPI-ACTIVEDIRECTORYCLIENT-L1-1-1.DLL
EXT-MS-WIN-NTUSER-MESSAGE-L1-1-0.DLL
EXT-MS-WIN-NTUSER-STRING-L1-1-0.DLL
EXT-MS-WIN-NTUSER-SYNCH-L1-1-0.DLL
EXT-MS-WIN-NTUSER-WINDOW-L1-1-0.DLL
EXT-MS-WIN-PROFILE-EXTENDER-L1-1-0.DLL
EXT-MS-WIN-RPC-SSL-L1-1-0.DLL
EXT-MS-WIN-RTCORE-NTUSER-SYSPARAMS-L1-1-0.DLL
EXT-MS-WIN-RTCORE-NTUSER-WINDOW-EXT-L1-1-0.DLL
EXT-MS-WIN-SECURITY-CAPAUTHZ-L1-1-1.DLL
EXT-MS-WIN-SECURITY-CHAMBERS-L1-1-0.DLL
EXT-MS-WIN-SECURITY-EFSWRT-L1-1-0.DLL
EXT-MS-WIN-SHELL32-SHELLCOM-L1-1-0.DLL
EXT-MS-WIN-WINRT-DEVICE-ACCESS-L1-1-0.DLL
hampelratte commented 6 years ago

I have another WIndows 10 installation, where it is actually working and dependency walker pretty much gave the same results. I don't think, my previous post is relevant :( , but how can we find out, what is missing?

Edit: I just tried a fresh Windows 10 installation. The only thing I installed was Java 1.8 and it works out of the box. This is a weird problem.

nguyenq commented 6 years ago

Since we can't reproduce the issue, it's tough to figure out what or where could be wrong.

A 4.0.3-SNAPSHOT has just been uploaded to Nexus Repository. The Windows binaries were built using VS2015. Please check it out or check out from the source. If it's a go for you, we'll release it asap.

nimeshbhatt commented 6 years ago

Hi, I am doing automation testing on android app (using appium) and in order to verify toast message I am using Tess4J 3.0.0, I've exactly the same problem. And on this line "result = instance.doOCR(imageFile);" I am getting this same error. (I debugged my script). Please help.

dawnfeifei commented 6 years ago

Hi, Win10 64bit, jdk 1.8.0_171 64bit, and I have tried all the method I googled on the net, still UnsatisfiedLinkError: at com.sun.jna.Native.loadLibrary(Native.java:481) at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(LoadLibs.java:84) at net.sourceforge.tess4j.TessAPI.(TessAPI.java:42)

kirans13 commented 6 years ago

@nguyenq I tried using 4.0.3-SNAPSHOT. I have VC++ 2015 installed. I am using Lept4j 1.9.4 . still getting Exception in thread "main" java.lang.UnsatisfiedLinkError: The specified module could not be found. at com.sun.jna.Native.open(Native Method) at com.sun.jna.Native.open(Native.java:1759) at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260) at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398) at com.sun.jna.Native.register(Native.java:1396) at com.sun.jna.Native.register(Native.java:1156) at net.sourceforge.tess4j.TessAPI1.(TessAPI1.java:41) at OCR.confidenceWord(OCR.java:106) at OCR.processImg(OCR.java:381) at test.main(test.java:7)

EDIT : I even checked with lept4j 1.10.0 , but still getting the same error. No dependency seems to be missing in dependency walker.

hskchaudhary commented 6 years ago

Facing the same issue with all releases of tess4j. Exception in thread "main" java.lang.UnsatisfiedLinkError: Error looking up function 'TessBaseAPICreate': The specified procedure could not be found.

at com.sun.jna.Function.<init>(Function.java:208)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:536)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:513)
at com.sun.jna.NativeLibrary.getFunction(NativeLibrary.java:499)
at com.sun.jna.Library$Handler.invoke(Library.java:199)
at com.sun.proxy.$Proxy0.TessBaseAPICreate(Unknown Source)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:284)

Tried both 64 bit & 32 bit DLLs as well Any Help would be appreciated.

hskchaudhary commented 6 years ago

Found a Good Workaround here: http://chillyfacts.com/simple-java-program-code-convert-image-text/

This uses tesseract cmd utility through java Got it working for me

nobleson commented 6 years ago

I will give it a trial

gao2009ss commented 6 years ago

runtime error Win7 32bit, jdk1.8.0_45 32bit , tess4j-4.2.1.jar,Microsoft Visual C++ 2015 Redistributable Update 3

12:14:58.634 [main] ERROR net.sourceforge.tess4j.Tesseract - null java.lang.NullPointerException: null at net.sourceforge.tess4j.Tesseract.dispose(Tesseract.java:819) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:239) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:194) at search.ocr.Test.main(Test.java:58) Exception in thread "main" net.sourceforge.tess4j.TesseractException: java.lang.NullPointerException at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:245) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:194) at search.ocr.Test.main(Test.java:58) Caused by: java.lang.NullPointerException at net.sourceforge.tess4j.Tesseract.dispose(Tesseract.java:819) at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:239) ... 2 more

nguyenq commented 6 years ago

@gao2009ss A NPE is usually a result of application code error. It would be helpful to see your code example.

jaimemunz commented 5 years ago

I looked EVERYWHERE without avail but I finally managed to get past this problem! I originally thought the problem was with the libtesseract3051 file but I fixed it by adding the liblept1744.dll file to my root project directory. This file was appearing in my C:\User\AppData\Local\Temp\tess4j\win32-x86-64 folder but could not be linked\found by my application for some reason. Hoping it helps other lost souls.

I am using eclipse and JDK 1.7

Project Outline is as follows: Tess4jProjectFolder |---JRE System Library |---src |---Referenced LIbraries |---liblept1744.dll |---libtesseract3051.dll

gobifox commented 5 years ago

Unable to load "libtesseract400.dll" file @Tess4j version 4.3.0 Env: Window 7 64-bit & JVM 8 64-bit Two files in the "C:\Users**\AppData\Local\Temp\tess4j\win32-x86-64" folder: libtesseract400.dll & liblept1760.dll And "Microsoft Visual C++ 2017 Redistributable @Version 14.16.27012" is installed

It cost me 3 days, no idea, help me plz~

Exception: UnsatisfiedLinkError @Native.open(libraryPath, openFlags); @NativeLibrary.java @171 line

gobifox commented 5 years ago

PS: Version 4.0.2 & 4.2.3 have the same problem, V3.5.2 works fine.

nguyenq commented 5 years ago

@gobifox Microsoft Visual C++ 2015, not 2017, is required. After installing that, you may want to delete Temp\tess4j\win32-x86-64 folder and try again.

gobifox commented 5 years ago

I did it according to your guide, but it still didn't work. @nguyenq Thanks

gobifox commented 5 years ago

@nguyenq This is my debug log:

--- v3.5.2 --- // Trace C:\Users\Chenin\AppData\Local\Temp\jna-2017317267\jna8617289419026386633.dll C:\Users\Chenin\AppData\Local\Temp\tess4j\win32-x86-64\libtesseract3052.dll C:\Users\Chenin\AppData\Local\Temp\tess4j\win32-x86-64\liblept1753.dll C:\Windows\System32\vcruntime140.dll C:\Windows\System32\api-ms-win-crt-runtime-l1-1-0.dll C:\Windows\System32\ucrtbase.dll C:\Windows\System32\api-ms-win-core-timezone-l1-1-0.dll C:\Windows\System32\api-ms-win-core-file-l2-1-0.dll C:\Windows\System32\api-ms-win-core-localization-l1-2-0.dll C:\Windows\System32\api-ms-win-core-synch-l1-2-0.dll C:\Windows\System32\api-ms-win-core-processthreads-l1-1-1.dll C:\Windows\System32\api-ms-win-core-file-l1-2-0.dll C:\Windows\System32\api-ms-win-crt-heap-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-string-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-stdio-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-convert-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-math-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-utility-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-environment-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-time-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-filesystem-l1-1-0.dll C:\Windows\System32\msvcp140.dll C:\Windows\System32\api-ms-win-crt-locale-l1-1-0.dll --- v3.5.2 --- // It works fine

--- v4.3.0 --- // Trace C:\Users\Chenin\AppData\Local\Temp\jna-2017317267\jna2157300319775130241.dll C:\Users\Chenin\AppData\Local\Temp\tess4j\win32-x86-64\libtesseract400.dll C:\Users\Chenin\AppData\Local\Temp\tess4j\win32-x86-64\liblept1760.dll C:\Windows\System32\vcruntime140.dll C:\Windows\System32\api-ms-win-crt-runtime-l1-1-0.dll C:\Windows\System32\ucrtbase.dll C:\Windows\System32\api-ms-win-core-timezone-l1-1-0.dll C:\Windows\System32\api-ms-win-core-file-l2-1-0.dll C:\Windows\System32\api-ms-win-core-localization-l1-2-0.dll C:\Windows\System32\api-ms-win-core-synch-l1-2-0.dll C:\Windows\System32\api-ms-win-core-processthreads-l1-1-1.dll C:\Windows\System32\api-ms-win-core-file-l1-2-0.dll C:\Windows\System32\api-ms-win-crt-heap-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-string-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-stdio-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-convert-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-math-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-utility-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-environment-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-time-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-filesystem-l1-1-0.dll C:\Windows\System32\msvcp140.dll C:\Windows\System32\api-ms-win-crt-locale-l1-1-0.dll --- v4.3.0 --- // throw UnsatisfiedLinkError, no more details

--- My test case --- LoadLibs.extractTessResources("win32-x86-64"); Native.loadLibrary("libtesseract400", TessAPI.class); --- My test case --- // Windows 7 64 bit SP1 + KB3125574(SP2) // JVM 8-162(64-bit) // Microsoft Visual C++ 2015 x86 and x64 Runtimes // No more..

I think there must be something wrong.

nguyenq commented 5 years ago

OK, I just performed a file compare on libtesseract.vcxproj file between the two versions (3.05.02 vs 4.0.0) and found one notable difference that is the extra tag in the 4.0.0:

<EnableEnhancedInstructionSet>AdvancedVectorExtensions</EnableEnhancedInstructionSet>

I'm not sure if that could make a difference, but several people had issues with loading libtesseract400.dll as reported here and at https://github.com/charlesw/tesseract/issues/427.

I'm about to go on vacation; I'll see if I could find time before that to recompile the DLL without that tag and put a SNAPSHOT on Nexus repository for you all to try out.

gobifox commented 5 years ago

OK, this issue has puzzled me for a time. Happy holidays! @nguyenq

nguyenq commented 5 years ago

https://github.com/tesseract-ocr/tesseract/issues/631 is the reason for that flag set.

Now that I removed the flag, I'm seeing "DotProductAVX can't be used on Android" error message again.

nguyenq commented 5 years ago

Only /arch:AVX (which is used in the release) and /arch:AVX2 (in 4.3.1-SNAPSHOT) options work. Other values for EnableEnhancedInstructionSet will result in "DotProductAVX can't be used on Android" error.

4.3.1-SNAPSHOT has been uploaded to https://oss.sonatype.org.

gobifox commented 5 years ago

I tried to update to 4.3.1-SNAPSHOT and run the test case, but the problem still exists.

com.sun.jna.Native.open(   "C:\Users\Chenin\AppData\Local\Temp\tess4j\win32-x86-64\libtesseract400.dll",   -1 ); // Throw UnsatisfiedLinkError in NativeLibrary.java @191

--- Test case --- LoadLibs.extractTessResources("win32-x86-64"); Native.load("libtesseract400", TessAPI.class); --- Test case ---

--- pom.xml --- <dependency>   <groupId>net.sourceforge.tess4j</groupId>   <artifactId>tess4j</artifactId>   <version>4.3.1-SNAPSHOT</version> </dependency>

<repositories>   <repository>     <id>53YF0210</id>     <url>https://oss.sonatype.org/content/repositories/snapshots/&lt;/url&gt;   </repository> </repositories> --- pom.xml ---

--- Load trace log --- C:\Users\Chenin\AppData\Local\Temp\jna-2017317267\jna3339796246471384985.dll C:\Windows\System32\api-ms-win-core-synch-l1-2-0.dll C:\Users\Chenin\AppData\Local\Temp\tess4j\win32-x86-64\libtesseract400.dll C:\Users\Chenin\AppData\Local\Temp\tess4j\win32-x86-64\liblept1760.dll C:\Windows\System32\vcruntime140.dll C:\Windows\System32\api-ms-win-crt-runtime-l1-1-0.dll C:\Windows\System32\ucrtbase.dll C:\Windows\System32\api-ms-win-core-timezone-l1-1-0.dll C:\Windows\System32\api-ms-win-core-file-l2-1-0.dll C:\Windows\System32\api-ms-win-core-localization-l1-2-0.dll C:\Windows\System32\api-ms-win-core-processthreads-l1-1-1.dll C:\Windows\System32\api-ms-win-core-file-l1-2-0.dll C:\Windows\System32\api-ms-win-crt-heap-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-string-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-stdio-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-convert-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-math-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-utility-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-environment-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-time-l1-1-0.dll C:\Windows\System32\api-ms-win-crt-filesystem-l1-1-0.dll C:\Windows\System32\msvcp140.dll C:\Windows\System32\api-ms-win-crt-locale-l1-1-0.dll --- Load trace log ---

gobifox commented 5 years ago

Is it possible to be related to the CPU? Hardware information: CPU: Intel Celeron N3050 @ 1.60GHz RAM: 8.00GB DDR3 @ 1599MHz Motherboard: Intel Corporation NUC5CPYB Graphics: Intel HD Graphics

nguyenq commented 5 years ago

Yes, that's the likely cause; the old CPUs do not support Enhanced Instruction Set.

gobifox commented 5 years ago

Got it, may be! Thanks for your help! :) :+1:

gobifox commented 5 years ago

PS: I checked my CPU and it didn't contain AVX instructions at all. confirmed! Instructions@Intel Celeron N3050: MMX, SSE, SSE2, SSE3, SSSE3, SSE4.1, SSE4.2, Intel 64, NX, VMX, AES

Advanced Vector Extensions - Wikipedia https://en.wikipedia.org/wiki/Advanced_Vector_Extensions

Achin1603 commented 5 years ago

We got the same issue. We followed the steps to get it working • Delete ‘win32-x86-64’ folder in ‘C:\Users\%username%\AppData\Local\Temp\tess4j’ • Change the tess4j version to ‘3.5.2’ • Change the lept4j version to ‘1.9.4’ • Build

nguyenq commented 5 years ago

libtesseract400.dll has been built in Visual Studio with /arch:AVX setting; therefore, it cannot be loaded on a non AVX-enabled CPUs, it has been determined.

We just found that tesseract.exe generated by vcpkg install tesseract:x64-windows-static, as described in the Wiki, runs fine on both AVX and non-AVX CPUs. Does anyone know how to build an equivalent static DLL using vcpkg? We believe it will help solve this DLL-loading issue with 4.0.0 versions.

nguyenq commented 5 years ago

tess4j-4.3.1 has been released to address this issue. Please try again.

nguyenq commented 5 years ago

Is this still an issue? Can it be closed?

harrys01 commented 5 years ago

I am still getting an error following the above mentioned fixes. Been stuck for 4 days now. Please help? Reproduced the issue using tess4j-4.3.1.

Achin1603 commented 5 years ago

The issue prevails even with 4.3.1. Can it be a problem with the lept4j version ? We are currently using 1.9.4

nguyenq commented 5 years ago

@harrys01 Did you install VC++ 2015? Please wipe out tess4j folder under your Temp folder and try again.

nguyenq commented 5 years ago

@Achin1603 If you're running on Windows, then yes, it's a version mismatch issue. libtesseract400.dll is linked against liblept1760.dll, which is included in lept4j-1.10.0.

phyrumsk commented 5 years ago

Hi, I try Tess4j 4.3.1 wrapper with Java. My System is Windows 10 64bit. I already installed JDK 1.8, Visual C++ 2015-2019 (x64) & JAR files that are included in the projects: lept4j-1.12.0.jar tess4j-4.3.1.jar jna-5.3.1.jar commons-io-2.6.jar ghost4j-1.0.1.jar jai-imageio-core-1.4.0.jar jboss-vfs-3.2.14.Final.jar jul-to-slf4j-1.7.26.jar log4j-1.2.17.jar pdfbox-2.0.12.jar pdfbox-tools-2.0.12.jar slf4j-api-1.7.26.jar slf4j-log4j12-1.7.26.jar

When calling "doOCR(imageFile)", It gave error "Exception in thread "main" java.lang.UnsatisfiedLinkError: The specified module could not be found."

I checked C:\Users\phyrum\AppData\Local\Temp\tess4j\win32-x86-64. There are : liblept1744.dll liblept1770.dll liblept1780.dll libtesseract3051.dll libtesseract400.dll

I don't know the real cause of this error. I've search and read some opened issues. but it can't help. Any suggestion or solution?

PeggySchmidtMittenzwei commented 5 years ago

Found a Good Workaround here: http://chillyfacts.com/simple-java-program-code-convert-image-text/

This uses tesseract cmd utility through java Got it working for me

Yes, it works fine after setting env. variable in System properties to TESSDATA_PREFIX C:\Program Files\Tesseract-OCR\tessdata

Ninjaneer324 commented 5 years ago
Exception in thread "main" java.lang.UnsatisfiedLinkError: The specified module could not be found.
    at com.sun.jna.Native.open(Native Method)
    at com.sun.jna.Native.open(Native.java:1759)
    at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:260)
    at com.sun.jna.NativeLibrary.getInstance(NativeLibrary.java:398)
    at com.sun.jna.Library$Handler.<init>(Library.java:147)
    at com.sun.jna.Native.loadLibrary(Native.java:412)
    at com.sun.jna.Native.loadLibrary(Native.java:391)
    at net.sourceforge.tess4j.util.LoadLibs.getTessAPIInstance(Unknown Source)
    at net.sourceforge.tess4j.TessAPI.<clinit>(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.init(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at net.sourceforge.tess4j.Tesseract.doOCR(Unknown Source)
    at pdfsorter.ImageReader.getImageReadings(ImageReader.java:34)
    at pdfsorter.PDFSorter.main(PDFSorter.java:25)

I have been getting the same problems however, Idk if this makes much difference but they stopped specifying line by line when they reach Tesseract in the error. pdfsorter is my package

System configuration:

Windows 10 64bit. JDK 1.8 Netbeans IDE 8.2 I have also found and downloaded all the required jar files and placed them into my project's libraries commons-io-2.6.jar jai-imageio-core-1.4.0.jar jna-4.1.0.jar jul-to-slf4j-1.7.25.jar lept4j-1.9.4.jar logback-classic-1.2.3.jar logback-core-1.2.3.jar slf4j-api-1.7.25.jar tess4j-3.4.8.jar

The instructions I originally followed are here: https://tphangout.com/how-to-use-the-tesseract-api-to-perform-ocr-in-your-java-code/

A little outdated and inaccurate as it skipped over including lept4j. My tess4j download had two folders for the .dll one folder for win32-x86 and another for win32-x86-64. Same situation with my lept4j download. I'm at a lost for what to do. I'll try the above solutions again but I would love new inputs.

nguyenq commented 5 years ago

Please follow the Tutorial. You do not need to mess with the library's source and DLLs. The dependencies will be automatically downloaded if you use a Maven project.