OpenCV build to java, not generating a java folder in build - java

I am trying to build OpenCV from source to .jar, since I need to have some contributed libs like Aruco (and these do not come with the default download from OpenCV.
Following a tutorial, I set up CMake, and configuring gives the following (pieces of) output:
OpenCV modules:
To be built: aruco bgsegm bioinspired calib3d ccalib core datasets dnn dnn_objdetect dpm face features2d flann fuzzy hfs highgui img_hash imgcodecs imgproc java java_bindings_generator line_descriptor ml objdetect optflow phase_unwrapping photo plot python_bindings_generator reg rgbd saliency shape stereo stitching structured_light superres surface_matching text tracking ts video videoio videostab xfeatures2d ximgproc xobjdetect xphoto
Disabled: js python3 world
Disabled by dependency: -
Unavailable: cnn_3dobj cudaarithm cudabgsegm cudacodec cudafeatures2d cudafilters cudaimgproc cudalegacy cudaobjdetect cudaoptflow cudastereo cudawarping cudev cvv dnn_modern freetype hdf matlab ovis python2 python2 sfm viz
Applications: perf_tests apps
Documentation: NO
Non-free algorithms: YES
...
Java:
ant: C:/opencv-3.4.1/apache-ant-1.10.5-bin/bin/ant.bat (ver 1.8.0)
JNI: C:/Program Files/Java/jdk1.8.0_171/include C:/Program Files/Java/jdk1.8.0_171/include/win32 C:/Program Files/Java/jdk1.8.0_171/include
Java wrappers: YES
Java tests: NO
Then after I run mingw32-make in the build folder configured by CMake, it builds without errors. Then in the build/bin folder I do find the opencv-341.jar file as expected.
When I link this library in my IntelliJ IDEA, the modules like org.opencv.aruco are recognised, as expected. However when trying to build the java project, I get this error:
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:389)
at com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:328)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:767)
Caused by: java.lang.UnsatisfiedLinkError: no opencv_java341 in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1867)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1122)
at AraInvaders.Main.main(Main.java:24)
... 11 more
After some research I figured that I forgot to link the native library location, as was also described in the tutorial. However according to that tutorial (and other resources), the build should include a build/java/x64 folder, containing a .dll file, however there is no build/java folder at all.
I do find a libopencv_java341.dll in build/lib however, linking that file does not resolve the problem. Image showing that .dll file is linked
When I download the Windows package form OpenCV, there is a Java folder in the build folder, and that does include the .jar file and an /x64 folder, however, those do not include the contributed libs, so that is why I am trying to build from source.
So the question is, what should I do to correctly setup the OpenCV library, including the contributed libs?

I asked on OpenCV forum http://answers.opencv.org/question/210451/opencv-401-face-module-for-java/.
So there are two solutions:
Since you built dynamically OpenCV libs, opencv_java.dll depends on opencv_core.dll, opencv_imgproc.dll, etc... you have to append the folder containing those to your system's PATH
Turn off BUILD_SHARED_LIBS flag and build everything again.

I renamed the generated dll from libopencv_java412.dll to opencv_java412.dll and it resolved the problem of library path problem ("UnsatisfiedLinkError").
The 412 in the file name is because I'm using OpenCV 4.1.2.

Related

jna4412392371053342294.dll: Can't find dependent libraries

When i was installing cassandra I encountered this error :
INFO [main] 2021-05-02 00:16:18,144 DatabaseDescriptor.java:775 - Back-pressure is disabled with strategy org.apache.cassandra.net.RateBasedBackPressure{high_ratio=0.9, factor=5, flow=FAST}.
Exception (java.lang.UnsatisfiedLinkError) encountered during startup: C:\Users\ASUS\AppData\Local\Temp\jna-2018896\jna4412392371053342294.dll: Can't find dependent libraries
java.lang.UnsatisfiedLinkError: C:\Users\ASUS\AppData\Local\Temp\jna-2018896\jna4412392371053342294.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817)
at java.lang.Runtime.load0(Runtime.java:810)
at java.lang.System.load(System.java:1088)
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:851)
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826)
at com.sun.jna.Native.<clinit>(Native.java:140)`enter code here
at org.apache.cassandra.utils.WindowsTimer.<clinit>(WindowsTimer.java:35)
at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:630)
at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:786)
ERROR [main] 2021-05-02 00:16:18,258 CassandraDaemon.java:803 - Exception encountered during startup
java.lang.UnsatisfiedLinkError: C:\Users\ASUS\AppData\Local\Temp\jna-2018896\jna4412392371053342294.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method) ~[na:1.8.0_282]
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1934) ~[na:1.8.0_282]
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1817) ~[na:1.8.0_282]
at java.lang.Runtime.load0(Runtime.java:810) ~[na:1.8.0_282]
at java.lang.System.load(System.java:1088) ~[na:1.8.0_282]
at com.sun.jna.Native.loadNativeDispatchLibraryFromClasspath(Native.java:851) ~[jna-4.2.2.jar:4.2.2 (b0)]
at com.sun.jna.Native.loadNativeDispatchLibrary(Native.java:826) ~[jna-4.2.2.jar:4.2.2 (b0)]
at com.sun.jna.Native.<clinit>(Native.java:140) ~[jna-4.2.2.jar:4.2.2 (b0)]
at org.apache.cassandra.utils.WindowsTimer.<clinit>(WindowsTimer.java:35) ~[apache-cassandra-3.11.10.jar:3.11.10]
at org.apache.cassandra.service.CassandraDaemon.activate(CassandraDaemon.java:630) [apache-cassandra-3.11.10.jar:3.11.10]
at org.apache.cassandra.service.CassandraDaemon.main(CassandraDaemon.java:786) [apache-cassandra-3.11.10.jar:3.11.10]
cd C:\Users\ASUS\Downloads\apache-cassandra-3.11.10-bin\apache-cassandra-3.11.10
java 1.8 and python 2.7 are installed
How can i solve this problem please
So I was able to find a conversations of how to deal with this out on GitHub:
https://github.com/MarkusBernhardt/proxy-vole/issues/35
Basically, (older versions of) the JNA DLL is dynamically linked to msvcrt100.dll. To get around this issue, the latest version of the JNA libraries should be installed (looks like it was fixed in JNA 4.3+).
Also, running Apache Cassandra on Windows can be difficult, and wrought with strange errors (as you are seeing). I highly recommend running it on Linux. If you must use Windows as your base OS, VirtualBox or Docker can help.
I resolved this problem by this way:
look at the tmp directory and quickly copy dll (in properties you can see its natural name), when it showing, before deleting.
dumpbin /dependents {name}.dll shows its dependents dll's
step by step find problem dll in windows directory and copy to {JDK_HOME}/bin. in my case it was msvcr100.dll, and it has several versions (x86, x64) - in first try, error change look, and i choose another.

java.lang.UnsatisfiedLinkError: Le module spécifié est introuvable.on Tess4J

I'm developing a web app using Spring MVC with Maven and with some functionality using tess4j for the OCR.
My dev environment:
Eclipse Neon.3
os: win server 2008R2
jvm 64 bit
apache tomecat 9
I downloaded the latest version of Tess4J from http://tess4j.sourceforge.net/ and imported it into eclipse. I am following this URL, I followed all the steps but when I try to execute it I am getting the following error:
java.lang.UnsatisfiedLinkError: Le module spécifié est introuvable.
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:75)
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:42)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:367)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:280)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:212)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:196)
I try to some tutorial and i add:
.MV C++ 2015 Redistributable (x64)
.I add on C:\Program Files (x86)\Apache Software Foundation\Tomcat 9.0\temp\tess4j\win32-x86-64
I still have the error.
What is essentially happening is System is not able to find a native module called 'spécifié' (I think, I can't read French) to load. Now the mechanics is like this. during load time somewhere (probably in the jar) a call is being made like
System.loadLibrary("spécifié");
Which is failing because the native library is not on PATH. So a simple solution would be to put the module on PATH. If it is an Windows environment, then the module would be a DLL file called spécifié.dll. This file must be placed on the path (e.g. set PATH=C:\xyz\spécifié.dll).
Try it and check.

Why am I only able to successfully load dynamic linking libraries using "-Djava.library.path=" in Linux but not Windows

I am using a library that requires that I load load dynamic linking libraries. My source code that uses these libraries is identical, the only difference is the operating system that I am using and which version of the library (Windows-64 version or Linux-64 version) that I am using. The library I am using provides 1 set for Windows ".dll" files and 1 set for Linux ".so" files, each in its own folder. To load the Linux ".so" libraries, I do
"-Djava.library.path=/home/johnmichaelreed/Desktop/Dropbox/Moved_Netbeans_Projects/Crazy_Client/Libjitsi_linux_64/lib/native/linux-64"
in the VM options and everything works.
Then, when I copy and paste the directory where the Windows ".dll" native libraries are into the VM options, I get rid of the Linux libraries path and insert:
-Djava.library.path=C:\Users\JohnReedLOL\Desktop\Dropbox\Moved_Netbeans_Projects\Crazy_Client\Libjitsi_windows_64\lib\windows_native\windows-64
I then change the library JAR files to the ones that came with the Windows version of the Library and I run the program and I get this error:
SEVERE: Failed to register custom Renderer org.jitsi.impl.neomedia.jmfext.media.renderer.video.JAWTRenderer with JMF.
java.lang.UnsatisfiedLinkError: C:\Users\JohnReedLOL\Desktop\Crazy_Client\Libjitsi_windows_64\lib\windows_native\windows-64\jnawtrenderer.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(ClassLoader.java:1937)
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1855)
at java.lang.Runtime.loadLibrary0(Runtime.java:870)
at java.lang.System.loadLibrary(System.java:1119)
at org.jitsi.impl.neomedia.jmfext.media.renderer.video.JAWTRenderer.<clinit>(JAWTRenderer.java:90)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:260)
at org.jitsi.impl.neomedia.device.DeviceConfiguration.registerCustomRenderers(DeviceConfiguration.java:1034)
at org.jitsi.impl.neomedia.device.DeviceConfiguration.<init>(DeviceConfiguration.java:355)
at org.jitsi.impl.neomedia.MediaServiceImpl.<init>(MediaServiceImpl.java:150)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:408)
at java.lang.Class.newInstance(Class.java:438)
at org.jitsi.impl.libjitsi.LibJitsiImpl.getService(LibJitsiImpl.java:142)
at org.jitsi.service.libjitsi.LibJitsi.invokeGetServiceOnImpl(LibJitsi.java:163)
at org.jitsi.service.libjitsi.LibJitsi.getMediaService(LibJitsi.java:115)
at outermost_crazy.Libjitsi_Main.<init>(Libjitsi_Main.java:124)
at outermost_crazy.Libjitsi_Main.main(Libjitsi_Main.java:827)
The weird thing is I am 100% sure that the native library path is the right place because when I print it using System.getProperty("java.library.path"), I get the folder:
C:\Users\JohnReedLOL\Desktop\Dropbox\Moved_Netbeans_Projects\Crazy_Client\Libjitsi_windows_64\lib\windows_native\windows-64
^ This folder definitely has all 12 .dll files ^. The library JAR files that I am using are the ones the ones that came with these 12 ".dll" files, not the ones that came with the Linux ".so" files, so I am pretty sure that I am using the right JAR files. Why this is error only happening on Windows with the .dll files, but not on Linux with the .so files?
Dependency Walker opening of jnawtrenderer.dll:

Unity-Android _ CommandInvokationFailure: Unable to convert classes into dex format

i'm using Windows 7, jdk 1.8.0 (64bit), jre 8 (64bit), Unity Pro 4.3.4f1 and Android SDK 22.6.1
All are updated softwares.
All works fine but when i use StartApp sdk, this error comes. No extra plugin is used, only the SDK provided by the StartApp ad.
Error building Player: CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details.
C:\Program Files\Java\jdk1.8.0\bin\java.exe -Xmx1024M -Dcom.android.sdkmanager.toolsdir="D:/android-sdks\tools" -Dfile.encoding=UTF8 -jar "C:/Program Files (x86)/Unity/Editor/Data/BuildTargetTools/AndroidPlayer\sdktools.jar" -
stderr[
UNEXPECTED TOP-LEVEL EXCEPTION:
java.lang.IllegalArgumentException: already added: Lcom/unity3d/player/a$1;
at com.android.dx.dex.file.ClassDefsSection.add(ClassDefsSection.java:122)
at com.android.dx.dex.file.DexFile.add(DexFile.java:161)
at com.android.dx.command.dexer.Main.processClass(Main.java:685)
at com.android.dx.command.dexer.Main.processFileBytes(Main.java:634)
at com.android.dx.command.dexer.Main.access$600(Main.java:78)
at com.android.dx.command.dexer.Main$1.processFileBytes(Main.java:572)
at com.android.dx.cf.direct.ClassPathOpener.processArchive(ClassPathOpener.java:284)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:166)
at com.android.dx.cf.direct.ClassPathOpener.processDirectory(ClassPathOpener.java:229)
at com.android.dx.cf.direct.ClassPathOpener.processOne(ClassPathOpener.java:158)
at com.android.dx.cf.direct.ClassPathOpener.process(ClassPathOpener.java:144)
at com.android.dx.command.dexer.Main.processOne(Main.java:596)
at com.android.dx.command.dexer.Main.processAllFiles(Main.java:498)
at com.android.dx.command.dexer.Main.runMonoDex(Main.java:264)
at com.android.dx.command.dexer.Main.run(Main.java:230)
at com.android.dx.command.dexer.Main.main(Main.java:199)
at com.android.dx.command.Main.main(Main.java:103)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at SDKMain.main(SDKMain.java:129)
1 error; aborting
]
I already tried JAVA_OPT and JAVA_HOME solutions. But still couldn't solved
I ran into this using IntelliJ 13.1.4, JDK 1.6 but I would guess that this is caused by the same thing on any other IDE -> classes.jar is referenced/included more than once.
Check and make sure that the classes.jar you added to the project (from Unity\Editor\Data\PlaybackEngines\androidplayer\bin\classes.jar) isn't referenced/included more than once. If you go into File->Project Structure:
There should only be one "classes" under libraries.
There should be NO reference to classes under Artifacts (Artifacts is used to create the plugin .jar file.)
Check out this related answer ->
https://stackoverflow.com/a/8437996/3464367
My issue was actually related to having duplicate files. Well not really duplicates, but I had 2 adMob sdk packages (different versions), that were getting into conflict. After deleting the older one, everything was fixed. Are you using any 3rd party SDK's or something similar, if so, try removing them if possible and see if the issue persists. Try to find out which part of the code is causing this to happen. You could ultimately try to compile an empty project just for testing.
Today I solved similar problem of Error building Player: CommandInvokationFailure: Unable to convert classes into dex format. See the Console for details. with adding .jar file into Plugins\Android\
I got different kind of errors:
Caused by: com.android.dx.cf.iface.ParseException: bad class file magic (cafebabe) or version (0034.0000 ...
Caused by: com.android.dx.cf.iface.ParseException: class name (ht/stringing/test) does not match path (src/ht/stringing/test.class)
My result working solution was similar to this:
Code lives here:
verysimple\src\ht\stringing\test.java
I do:
> javac -classpath "c:\Android\sdk\platforms\android-15" ht\stringing\test.java
> jar cvf ..\dist\verysimple.jar ht\stringing\test.class
> copy ..\dist\verysimple.jar c:\ExUnityApp\Assets\Plugins\Android
Don't forget to compare your 'Minimum Api Level' in Player Setting. For me it was Android 4.0.3 ... (15)

OpenCV Classpath in Netbeans

i just started working with JavaCV under MacOSX. I compiled OpenCV with CMake from the latest source and put the path where the libraries are into the -Djava.library.path=\path\to\libraries JVM Argument and added the JavaCV Libraries in my Project Settings. I also tried several other Variation of the Classpath. But when i launch an easy Project to just grab one image from my webcam i get following error:
Exception in thread "Thread-3" java.lang.UnsatisfiedLinkError: no jnivideoInputLib in java.library.path
at java.lang.ClassLoader.loadLibrary(ClassLoader.java:1758)
at java.lang.Runtime.loadLibrary0(Runtime.java:823)
at java.lang.System.loadLibrary(System.java:1045)
at com.googlecode.javacpp.Loader.load(Loader.java:358)
at com.googlecode.javacpp.Loader.load(Loader.java:285)
at com.googlecode.javacv.cpp.videoInputLib.<clinit>(videoInputLib.java:80)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:169)
at com.googlecode.javacpp.Loader.load(Loader.java:305)
at com.googlecode.javacpp.Loader.load(Loader.java:285)
at com.googlecode.javacv.cpp.videoInputLib$videoInput.<clinit>(videoInputLib.java:192)
at com.googlecode.javacv.VideoInputFrameGrabber.start(VideoInputFrameGrabber.java:89)
at webcampong.Grabber.run(Grabber.java:35)
at java.lang.Thread.run(Thread.java:680)
It is due to the compatibility issue of your openCV and javaCV libraries.
Try to download compatible openCV libraries (containing bin folder).
VideoInputFrameGrabber works only under Windows.
As stated in JavaCV's README.txt:
New videoInputLib wrapper and corresponding VideoInputFrameGrabber to capture using DirectShow, useful under Windows 7 where OpenCV and FFmpeg can fail to capture using Video for Windows (issue #58)
I use javacpp and videoinput to manipulate cameras. I got the error 'java.lang.UnsatisfiedLinkError: no jnivideoInputLib in java.library.path' when I call 'videoInput.listDevices()'.
I fix the problem by adding codes like:
org.bytedeco.javacpp.Loader.load(org.bytedeco.javacpp.opencv_highgui.class);
System.out.println(videoInput.listDevices());
you must call 'Loader.load' first before you call other methods, I don't know why.

Categories

Resources