"Java.lang.UnsatisfiedLinkError: no opencv_java320 at java.library.path"
I have a selenium test that, when it finishes, does some operations with OpenCV. With IntelliJ IDEA, it works fine, the process is correct, but when I try to execute via the command line (for using Jenkins in the near future), I get the above error:
"Java.lang.UnsatisfiedLinkError: no opencv_java320 at java.library.path"
I read other questions here and I set the java.library.path to the path where the jar and dll files are located, but the error still comes up and I'm running out of ideas.
Could you help me?
Thank!
source to share
Below is a working snippet. What do you need to adapt to your needs.
accept the following file structure
libs\opencv_java320.dll
pom.xml
src\test\java\sub\optimal\OpenCVTest.java
pom.xml - part for testing
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<argLine>-Djava.library.path=${project.basedir}/libs/</argLine>
</configuration>
</plugin>
</plugins>
</build>
sub \ optimal \ OpenCVTest.java
package sub.optimal;
import org.junit.Test;
public class OpenCVTest {
@Test
public void someOpenCVTest() {
System.out.printf("java.library.path: %s%n",
System.getProperty("java.library.path"));
System.loadLibrary("opencv_java320");
}
}
run test
mvn compile test
Output
...
[INFO] -------------------------------------------------------
[INFO] T E S T S
[INFO] -------------------------------------------------------
[INFO] Running sub.optimal.OpenCVTest
java.library.path: X:\develop\opencv-demo/libs/
[INFO] Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: ...
...
source to share
If you are using STS / Eclipse or any IDE, follow the instructions to resolve the unsatisfiedlinkerror-no-opencv-java320 error .
Window -> Preferences -> Custom Libraries -> New -> Create New Library As Attached Image
Note : - When creating a new library, the location of the Jar file and the location of the native library (opencv / build / java / x64) should be exactly the same.
source to share
If you are using IntelliJ IDEA you must add OpenCV library as Native Library Location.
- Go to
File
>Project Structure
- In the sidebar, select
Modules
and then select the tabDependencies
- Click the icon
+
below to add a dependency. Then select an optionAdd JARS or directories
. -
Then navigate to the path where you installed OpenCV and select
build/bin/opencv-***.jar
(or build / java / opencv - ***. Jar in some case) and clickOpen
.※ If you cannot find this jar file. I predict that you forgot to build the OpenCV repo. Link to this introduction
-
It will show up as a dependency in the window. Now we also need to add the Native Library location. To do this, double click on opencv - ***. Jar
- Then click the icon
+
to add your own library location. - Then go to the location where you installed OpenCV and select
build/lib
(in somecase it will bebuild/java/x64
). Now clickOpen
.
Now you can use System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
to load the library as expected
Ref: How to set up OpenCV in IntelliJ IDEA in Aadam
PS: You can also add java.library.path
to the VM variant like-Djava.library.path={PATH_T0_LIBRARY}
source to share
This worked for me. I am using Intellij on Mac
import org.opencv.core.CvType;
import org.opencv.core.Mat;
public class Test {
public static void main(String[] args){
//System.loadLibrary(Core.NATIVE_LIBRARY_NAME); - REMOVE THIS
nu.pattern.OpenCV.loadShared(); //add this
Mat mat = Mat.eye(3, 3, CvType.CV_8UC1);
System.out.println("mat = " + mat.dump());
}
}
And addiction
<dependency>
<groupId>org.openpnp</groupId>
<artifactId>opencv</artifactId>
<version>3.2.0-0</version>
</dependency>
source to share