5

So I built a vision library on windows, and I've ran it on Windows and it ran okay. I used the command:

java -jar LiftTracker.jar

I transferred the .jar file I built on windows over to a Raspberry Pi, and did a make install to install the opencv libraries. Once I did that, I tried to do the same command as above and came up with the error:

java.lang.UnsatisfiedLinkError: no opencv_java310 in java.library.path.

I did some research and found that I could run this command along side the -jar command

java -Djava.library.path=/path/to/dir

That still did not work. Is it the way that I am importing the system library? The way I'm importing it in the code is by:

static{ 

    System.loadLibrary("opencv_java310");

}

I think the main reason that it's not working is because of the way I installed opencv. Any ideas?

Thanks!

2
  • Use this instead. System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Commented Feb 28, 2017 at 1:57
  • @Je-ArZamora that was the original line i used, still didn't work Commented Feb 28, 2017 at 2:11

2 Answers 2

3

You need to add "libopencv_java320.so" to your java project libs. It is around 1mb additional library.

  1. You can generate this .so file from sources as per documentation: https://opencv-java-tutorials.readthedocs.io/en/latest/01-installing-opencv-for-java.html#install-opencv-3-x-under-linux

  2. another way is to build sources manually using terminal cmake (it will download around 4gb of opencv sources), should be easy: download the source from opencv: http://opencv.org/releases.html Unzip it and inside unpacked directory create a /build directory like this ../opencv-3.2.0/build/. Make sure you have cmake installed (Debian/Ubuntu apt get install cmake). Open terminal in previously created /build folder and type: cmake -DBUILD_SHARED_LIBS=OFF .. after operation finishes type make -j8 and after that "libopencv_java_320" should be generated for 3.2.0 version - copy this .so into your java project. Last type make install from the same build directory to install 3.2.0 libs on the system (you might want to previously remove older version if necessary). More info here: https://elbauldelprogramador.com/en/compile-opencv-3.2-with-java-intellij-idea/

  3. same as above approach but automated will be by using this script: https://github.com/milq/milq/blob/master/scripts/bash/install-opencv.sh Script does also install opencv on the linux system. Took it from this source: http://milq.github.io/install-opencv-ubuntu-debian/ It does much more then 2nd approach, should be easiest to make.

After installing opencv libs in system and copying libopencv_java320.so into your java project you can remove sources (it is almost 4gb after all).

Then you can use below code in your main method to load windows .dll (if you previously added it too) and linux .so:

String libName = "";
if (SystemUtils.IS_OS_WINDOWS) {
    libName = "opencv_java320.dll";
} else if (SystemUtils.IS_OS_LINUX) {
    libName = "libopencv_java320.so";
}
System.load(new File("./libs/".concat(libName)).getAbsolutePath());
Sign up to request clarification or add additional context in comments.

1 Comment

Added .so lib to my dropbox, feel free to download it. Not really sure if it will work if you have installed different version than 320 of opencv on your linux system, but it is worth a try if you don't want to build all the 4gb of sources just for this one file: dropbox.com/s/9nlfaornihy6zun/libopencv_java320.so?dl=1
1

if you builded OpenCV on OS;

1) set opencv and java variable

  • JAVA_HOME = the directory containing your JDK

  • ANT_HOME = the directory in which Apache Ant is installed

  • OPENCV_HOME = the directory in which all of OpenCV is installed

  • OPENCV_LIB = the directory containing all native JNI libraries

  • OPENCV_JAR = the path to the JAR file containing the java interface to OpenCV (typically named something like "opencv-320.jar" )

    • OPENCV_HOME will be at /home/opencv-3.2.0

    • OPENCV_JAR will be at ${OPENCV_HOME}/build/bin/opencv-320.jar

    • OPENCV_LIB will be at ${OPENCV_HOME}/build/lib

2) Load Native Library

 System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

3) Run your application

java -Djava.library.path=${OPENCV_LIB} -jar myapp.jar

https://github.com/WPIRoboticsProjects/GRIP-code-generation/tree/master/java

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.