I'm using Windows 7 and getting this exception when trying to run a Java project that uses opencv libraries:
Exception in thread "main"
java.lang.UnsatisfiedLinkError: no opencv_java 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.opencv.highgui.Highgui.<clinit>(Highgui.java:416)
at teste.main(teste.java:21)
What did I do wrong? Is some import missing?
I want to create a simple Java project in Eclipse (not Android), that uses openCV.
This exception is raised because the system is trying to find native libraries that OpenCV needs for this specific platform, and does not find them.
Exception in thread "main"
java.lang.UnsatisfiedLinkError: no opencv_java in java.
To solve this error:
If you are using version >= opencv 2.4.6, then the jar has a constant variable in Core class named NATIVE_LIBRARY_NAME that you give to the loadLibrary()
function in FaceDetector class to include features of opencv in your project, you probably already have this:
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
Using the above named constant, there is no need to remember name of strang dll files.
Add the opencv 2.4.9.jar
to the build path from project preferences as:
Window -> Preferences -> Java Build Path –> Add Library -> User Libraries ->
User Library -> & click New
You will see a dialog as below. Add opencv-2.4.9 as Library Name & click Ok.
Then Add External Jar
& locate your opencv jar & click ok. Then expand opencv-2.4.9.jar & click on Native Library Location (None) as shown below :
Necessary step: enter the location of the folder containing native library used by "opencv-2.4.9" & then click OK as shown below :
So now the jar now has all the native libraries it needs to do the work. Rebuild the java program and everything should compile and run as designed.
If you get this error:
Exception in thread "main"
java.lang.UnsatisfiedLinkError: no opencv_java in java.library.path
It probably means you are shooting from the hip, programming by brownian motion, trying to get openCV to work. Like trying to figure out how an airplane works in flight by pressing all the buttons furiously. You're going to have a bad time.
What the error means:
Eclipse is telling you that the jar file can't find libraries it needs to do its job. So naturally it's not going to work until you make them available. You've got to find a tutorial on "how to build openCV from source" on your particular platform: (windows, mac, linux, etc), (32bit, 64bit, etc).
Basically, you glossed over the 'Native library location' settings, or didn't set them correctly, and so the jar can't find its support libraries written in C
.
How do fix it, thousand foot view:
build/lib
directory under the path where you built openCV from source. This blog talks about the steps above in step-by-step detail: https://udallascs.wordpress.com/2014/03/30/adding-opencv-and-configuring-to-work-with-eclipse-and-java/
Why can't this just be a simple jar?
Because most of openCV is written in the C
programming language. And the jar file you are using is just a window into that C world. So it's a rube Goldberg machine. You'll see these sorts of things all over the place in the real work world, so pay attention, you are getting an education here.
Trying to load the library by doing this:
System.loadLibrary("opencv_java244")
Or by doing this:
System.loadLibrary("opencv_java244")
Didn't work - still got the same error.
Finally what worked was providing the full path to the dylib file and using:
System.load(new File("/usr/local/Cellar/opencv/2.4.10.1/share/OpenCV/java/libopencv_java2410.dylib").getAbsolutePath());'
I'm using HomeBrew but however you installed it just find the file and uddate the path.
I find solution. Actual dll is located at openCV\opencv\build\java\x64\
folder. In my case its name is opencv_java247.dll , So i have changed java code line
System.loadLibrary("opencv_java244")
to
System.loadLibrary("opencv_java247")
I also set native library location as E:/Sagar_tools/tools/openCV/opencv/build/java/x64
(full path to dll) in build path.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With