OpenCV Classpath in Netbeans - java

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.

Related

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

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.

Mediainfo Java wrapper from filebot does not work in my code

I want to get information about video so I come to know that, mediainfo is good option. I try to use it java. So I fins the MediaInfo.java a wrapper around the native library mediainfo.s.0 I have ubuntu 16.04 64bit and the library are also 64bit. I get code from the filebot git project and put the native library in resource path. But still I get the error.
Exception in thread "main" com.mediainfo.MediaInfoException: Unable to
load amd64 (64-bit) native library libmediainfo.so: Unable to load
library 'mediainfo': Native library (linux-x86-64/libmediainfo.so) not
found in resource path`
`Caused by: java.lang.UnsatisfiedLinkError: Unable to load library
'mediainfo': Native library (linux-x86-64/libmediainfo.so) not found in
resource path
at com.sun.jna.NativeLibrary.loadLibrary(NativeLibrary.java:271)
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.mediainfo.MediaInfoLibrary.<clinit>(MediaInfoLibrary.java:23)
at com.mediainfo.MediaInfo.<init>(MediaInfo.java:22)
... 1 more
I put both libmediainfo.so.0 and libzen.so.0 in /usr/lib directory in my system and then check.
The error for zen library is solved but the error for mediainfo library is still there. The code to load these library is as below
Library LIB_ZEN = Platform.isLinux() ? (Library) Native.loadLibrary("zen", Library.class) : null;
MediaInfoLibrary INSTANCE = (MediaInfoLibrary) Native.loadLibrary("mediainfo", MediaInfoLibrary.class, singletonMap(OPTION_FUNCTION_MAPPER, new FunctionMapper() {
#Override
public String getFunctionName(NativeLibrary lib, Method method) {
// MediaInfo_New(), MediaInfo_Open() ...
return "MediaInfo_" + method.getName();
}
}));
So I am not able to solve this problem. I try very hard to solve this.

Matlab has critical error from clean install (possibly OS X related?)

Using R2014b on OS X Yosemite.
Exception in thread "Startup Class Loader" java.lang.UnsatisfiedLinkError: jogamp.common.jvm.JVMUtil.initialize(Ljava/nio/ByteBuffer;)Z
at jogamp.common.jvm.JVMUtil.initialize(Native Method)
at jogamp.common.jvm.JVMUtil.<clinit>(JVMUtil.java:58)
at com.jogamp.common.os.Platform$1.run(Platform.java:212)
at java.security.AccessController.doPrivileged(Native Method)
at com.jogamp.common.os.Platform.<clinit>(Platform.java:179)
at javax.media.opengl.GLProfile.<clinit>(GLProfile.java:83)
at com.mathworks.hg.peer.JavaSceneServerPeer.initializeJOGL(JavaSceneServerPeer.java:114)
at com.mathworks.hg.peer.JavaSceneServerPeer.<clinit>(JavaSceneServerPeer.java:100)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:190)
at com.mathworks.mde.desk.StartupClassLoader.loadClass(StartupClassLoader.java:258)
at com.mathworks.mde.desk.StartupClassLoader.access$900(StartupClassLoader.java:25)
at com.mathworks.mde.desk.StartupClassLoader$2.run(StartupClassLoader.java:244)
at java.lang.Thread.run(Thread.java:745)
This pops up the moment I start matlab. I am unable to use imagesc() or imshow() and probably loads of other functions, because matlab crashes with Caught unexpected exception of unknown type. instantly.
I'm at my wits end. The matlab install is fresh, and so is the OS. Same problem using the Java from Apple or the Java from Oracle.
EDIT: Response from MathWorks is that integration with Maple breaks everything. Emptying the .maplerc.sh file in the /bin/ directory fixes everything.
This issue is caused by having installed Matlab integration through maple. A file called .maplerc.sh is placed within the /bin/ folder in the matlab .app, and it apparently breaks everything. You cannot delete the file (this causes matlab to not launch on start up) but you can erase its contents. This will create an error upon launch, but you can ignore it and everything will work fine.
Uninstall matlab and maple, and reinstall maple and matlab without integration will fix the issue entirely.
Replace the contents of the file /Applications/MATLAB_R2014b.app/bin/.maplerc.sh by an empty line (as suggested by the other answer from Dorako), and
Modify the file /Applications/MATLAB_R2014b.app/toolbox/local/matlabrc.m, by searching for Maple in this text file and comment-out or remove the part between the two lines containing %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%.
The second step ensures that there is no error or warning message any more on startup, so that re-installing the programs is not necessary.

com4j on Windows 64 bit

I've downloaded the latest com4j jars and I'm trying to run through the most simple of their examples.
I'm on Windows 7 64 bit and using a 64 bit JVM.
When I run the command (from the com4j tutorial):
java -jar tlbimp.jar -o wsh -p test.wsh %WINDIR%\system32\wshom.ocx
I get:
Exception in thread "main" java.lang.UnsatisfiedLinkError: com4j-amd64.dll: %1 is
not a valid Win32 application
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com4j.COM4J.loadNativeLibrary(COM4J.java:569)
at com4j.COM4J.<clinit>(COM4J.java:522)
at com4j.tlbimp.driver.Lib.getLibid(Lib.java:90)
at com4j.tlbimp.driver.Driver.addLib(Driver.java:38)
at com4j.tlbimp.driver.Main.doMain(Main.java:123)
at com4j.tlbimp.driver.Main.main(Main.java:56)
Exception in thread "Com4J shutdown hook" java.lang.NoClassDefFoundError: Could
not initialize class com4j.COM4J
at com4j.COM4J$3.run(COM4J.java:476)
The java code extracts "com4j-amd64.dll" next to the jar.
The latest version has just been released:
http://kohsuke.org/2012/04/27/com4j-updates/
https://github.com/kohsuke/com4j/downloads
Using this one solved all my problems.
You have two options:
Download and use the full latest version (located here:
https://github.com/kohsuke/com4j/downloads)
Extract the latest com4j-amd64.dll from the most recent version
Download the latest version (located here: https://github.com/kohsuke/com4j/downloads).
Open up the com4j.jar with your favorite zip utility (read 7zip)
Extract com4j.jar\com4j\com4j-x64.dll to the base directory of your application
(optional) Register the dll using REGSVR32 <path to dll>\com4j-x64.dll
I had a similar result at first. I found the com4j-amd64.dll that is produced by com4j is empty. The remedy is to extract the file from the com4j jar file, and put it in the relevant directory by manual action. Com4j will then not auto-produce the file since it is already there. So check if the file is empty as a first step -Carl

Eclipse / Java path problems

I'm currently following the third tutorial listed here: here
where I'm trying to compile some matlab code into Java classes. Creating a project in eclipse, and correctly linking the libraries (exactly how its done in the tutorial). Everything actually compiles, but when I run the program I get an Unsatisfied Link error.
Exception in thread "main" java.lang.UnsatisfiedLinkError: Can't load library: C:\Program Files\MATLAB\R2009b\bin\win32\BuilderJABootstrap.dll
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.load0(Unknown Source)
at java.lang.System.load(Unknown Source)
at com.mathworks.toolbox.javabuilder.internal.MWMCR.<clinit>(MWMCR.java:1571)
at com.demo.DemoMCRFactory.<clinit>(DemoMCRFactory.java:100)
at com.demo.MLTestClass.<init>(MLTestClass.java:62)
at Driver.main(Driver.java:16)
The troubling part is the Can't load library: as the path provided '\win32' is not a legitimate path on my computer as I have a 64 bit machine, so the dll is located at \win64. However, I've triple checked all my Environmental variables and am kind of stuck. Could I be using a 64-bit version of matlab, with a 32-bit library?
Thanks!
ChrisH's solution was it

Categories

Resources