Opencv Java exception

Hello I’m getting next exception when trying to run 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)

Can it be caused of wrong installation of opencv? Or maybe some import is missing? I’m trying to follow instructions from here. Also I’m using Windows 7 and I want to create a simple Java project in Eclipse(not Android)

  • So I’ve extracted javacv from OpenCV-2.4.2.exe file to C:/
  • Then executed “cmake -G “MinGW Makefiles” -DBUILD_opencv_java=ON C:/opencv” command and after that, “mingw32-make”. Everything was build without errors or warnings
  • After I’ve added opencv dll’s to my Environment Variables

Thanks for your attention

opencv perspectiveTransform function exception

how to use the perspectiveTransform function? when run my code, Will produce the following exception: OpenCV Error: Assertion failed (scn + 1 == m.cols && (depth == CV_32F || depth == CV_64F)



OpenCV cvCanny memory exception

I am trying to do the examples in the OpenCV book and I got to the part regarding cvCanny. I am trying to use it, but I keep getting a memory exception error of Unhandled exception at 0x75d8b760 in I

OpenCV Stitcher Class – Unhandled exception

I am trying to run the code below in Debug and keep getting the following exception : Unhandled exception at 0x10210579 (opencv_core246d.dll), Access violation #include <opencv2/opencv.hpp> #inc

OpenCV mat::at throwing exception

This code only throws an exception in Debug mode. In Release, it gives the expected output of 0. #include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace std;

opencv gives exception with cvFindStereoCorrespondenceBM

I wrote a code to find disparity map from two images left and right; and saving the map in stereo. The code seems okay to me but somehow I’m getting exception: On the terminal window: OpenCV Er

Exception thrown for cvCalcOpticalFlowHS() opencv

Heey, I’m trying to sort out the function of Optical Flow of openCV, but for some reason I’m getting an exception in visual studio: Unhandled exception at 0x772615de in Optical_flow.exe: Microsoft C+

Opencv java interface has no “VideoWriter” class

official opencv java homepage: http://opencv.org/opencv-java-api.html opencv javadoc: http://docs.opencv.org/java/ I just find VideoCapture class, but no VideoWriter class, so can only capture one

OpenCV for Android: Sample Project ClassNotFound Exception

I’m trying to run a sample from opencv for android. It’s not working. java.lang.RuntimeException: Unable to instantiate activity ComponentInfo{org.opencv.samples.puzzle15/org.opencv.samples. puzzle15

Java OpenCV Bindings

I am looking for OpenCV java bindings, all the references point to the processing library. I know processing is java but isn’t there a standalone java lib? or should just use processing libs?

OpenCV + Java = UnsatisfiedLinkError

I need capture a video stream from my USB webcam, for this i use Opencv 2.4.6 for developing in Java. I follow the steps listed in here I add the C:/opencv/build/java/x64 dir to my System PATH and i

Answers

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.

The below exception is raised because system is trying to get Java build of OpenCV for specific platform.

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java in java.

To solve this error :-

  1. If you are using opencv version < opencv 2.4.6 then answer given by @user3033420 will gives solution.
  2. If >= opencv 2.4.6 is used, then it has constant in Core class named NATIVE_LIBRARY_NAME. You can give this constant name to loadLibrary() function in FaceDetector class to include features of opencv in your project as :-

    System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
    

Using the named constant, there is no need to remember name of dll file.

Then add opencv 2.4.9.jar in 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.

Opencv Java exception

Then click on 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 :-

Opencv Java exception

Now, enter the location of the folder containing native library used by “opencv-2.4.9” & then click OK as shown below :-

Opencv Java exception

Hope this will help to solve the above error.

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:

  1. Download the source code for openCV for your operating system.
  2. Follow the directions to build openCV from source.
  3. Copy the jar into a lib directory in your Java project.
  4. Configure the jar to look for its native libraries by setting the “native library location” to the build/lib directory under the path where you built openCV from source.
  5. Clean build the java project, and the UnsatisfiedLinkError should go away.

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.

The function loadlibrary tries to find the name of the the DLL in your PATH variable — check the DLL name. You can also try System.loadLibrary(Core.NATIVE_LIBRARY_NAME);