0

The Java example provided with OpenCV called HelloCV doesn't work. This is the example:

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Mat;

public class Main {

    public static void main(String[] args) {
        System.out.println("Welcome to OpenCV " + Core.VERSION);
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
        Mat m  = Mat.eye(3, 3, CvType.CV_8UC1);
        System.out.println("m = " + m.dump());
    }

}

The output throws UnsatisfiedLinkError, what is this error and how do I solve it. I had to build the OpenCV jar file, I thought I did it correctly but I could have done something wrong when building the library.

1 Answers1

0

EDIT 1: I just found this question and it has an answer with a better solution. I'm going to try it since it looks more elegant.


Are you using Maven? I had the same problem with Java + Maven. It couldn't find the OpenCV library, so I bypassed this problem by putting the libopencv_java249.so (in my case) in the root directory of the project and loaded it with the following code:

private static void loadOpenCV() throws IOException {
    File curDir = new File(".");
    System.load(curDir.getCanonicalPath() + "/libopencv_java249.so");
}
luizfzs
  • 1,328
  • 2
  • 18
  • 34