1

I'm trying to include the openCV library on a little java code. Since I'm not using any IDE, I compile using the following command:

$ javac -cp $CLASSPATH:/usr/local/Cellar/opencv/2.4.12/share/OpenCV/java/opencv-2412.jar Webcam.java

(I installed openCV using brew)

and it compiles just fine, but the moment I run it, throws:

Exception in thread "main" java.lang.UnsatisfiedLinkError: no opencv_java2412 in java.library.path

from this line:

System.loadLibrary("opencv_java2412");

Could somebody help me?

----- EDIT -----

I've also tried using:

$ export CLASSPATH=$CLASSPATH:/usr/local/Cellar/opencv/2.4.12/share/OpenCV/java/opencv-2412.jar 

then:

$ javac Webcam.java
$ java Webcam

getting the same result

4
  • What command are you using to run your program? Are you making sure that opencv-2412.jar is on your classpath at runtime, as well as at compile time? Commented Sep 10, 2015 at 20:15
  • Just 'java Webcam' :o how do I add it at runtime? Commented Sep 10, 2015 at 20:18
  • Did your opencv installation come with some sort of native library for use at runtime? I notice that the jar is called opencv-2412.jar, but the library you're trying to load is opencv_java2412. Try looking around in your OpenCV directory for a lib directory or something? Commented Sep 10, 2015 at 20:41
  • If that doesn't work, I'm out of ideas. I hope someone with more mac/osx knowledge comes along. Commented Sep 10, 2015 at 20:42

3 Answers 3

1

I finally solve it loading the lib directly from the code, replacing:

System.loadLibrary("opencv_java2412");

with

System.load("/usr/local/Cellar/opencv/2.4.12/share/OpenCV/java/libopencv_java2412.dylib");
Sign up to request clarification or add additional context in comments.

Comments

1

I see the accepted answer does work, but I've just run into this problem too and thought I should write down what I did. I installed OpenCV with Homebrew too, so my libraries are in the same place as above.

Yes, you need to set the java.library.path, e.g. (I'm using OpenCV 3.1.0 here):

-Djava.library.path=/usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/java

In the code examples I've seen the library is loaded in Java:

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

Where Core.NATIVE_LIBRARY_NAME resolves to "opencv_java310". The native library names its actually looking for are:

libopencv_java310.dylib

or if that's not found then:

libopencv_java310.jnilib

However, Homebrew only provided libopencv_java310.so and needed a symbolic link:

cd /usr/local/Cellar/opencv3/3.1.0_3/share/OpenCV/java

ln -s libopencv_java310.so libopencv_java310.dylib

After that things started working.

Comments

0

You can use -Djava.library.path=PATH_TO_YOUR_LIBS options Actually, you can unpack .so files (libs) and set path to this libraries.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.