Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"Java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path"

I have a selenium test that when it finishes makes some operations with OpenCV. With IntelliJ IDEA it works fine, the operations process correctly, but when I try to execute through command line (for Jenkins use in the near future), I get the error mentioned above:

"Java.lang.UnsatisfiedLinkError: no opencv_java320 in java.library.path"

I read the other questions on here and I've set up the java.library.path to the path where the jar and dll files are, but the error still comes up and I'm running out of ideas.

Could you please help me?

Thanks!

like image 300
viktors89 Avatar asked Jul 03 '17 11:07

viktors89


3 Answers

Please find below a working snippet. Which you need to adapt to your needs.

assume following file structure

libs\opencv_java320.dll
pom.xml
src\test\java\sub\optimal\OpenCVTest.java

pom.xml - the part for the 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 the 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: ...
...
like image 56
SubOptimal Avatar answered Nov 14 '22 23:11

SubOptimal


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 dependency

<dependency>
   <groupId>org.openpnp</groupId>
   <artifactId>opencv</artifactId>
   <version>3.2.0-0</version>
</dependency>
like image 44
VK321 Avatar answered Nov 14 '22 23:11

VK321


If you are using STS/Eclipse or any IDE then follow the steps to getting solve your unsatisfiedlinkerror-no-opencv-java320 error.

Window -> Preferences -> User Libraries -> New -> create new Library Like attached Image

Note:- Jar location and Native Library Location (opencv/build/java/x64) should be exactly like this while creating the new library.

enter image description here

like image 33
Ankit Gupta Avatar answered Nov 15 '22 00:11

Ankit Gupta