OpenCV desktop Java bindings on Windows 7 - UnsatisfiedLinkError

asked 2015-03-09 10:31:14 -0600

I'm new to OpenCV and tried installing the desktop Java bindings, but my code fails when I try to instantiate anything from the native library included in the build. My code is pretty basic:

import org.opencv.objdetect.CascadeClassifier;

public final class OpenCVTest {
    static {
        System.load("C:\\Program Files\\opencv\\build\\java\\x64\\opencv_java2411.dll");
    }

    public void process(String s) {
        CascadeClassifier cc = new CascadeClassifier();
        CascadeClassifier faceDetector = new CascadeClassifier("C:\\Program Files\\opencv\\sources\\data\\haarcascades\\haarcascade_frontalface_alt.xml");
    }

    public static void main(String[] arguments) {
            OpenCVTest test = new OpenCVTest();
            for (String s : arguments)
                test.process(s);
    }
}

It compiles fine, but when I run it --

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0()J
        at org.opencv.objdetect.CascadeClassifier.CascadeClassifier_0(Native Method)
        at org.opencv.objdetect.CascadeClassifier.<init>(CascadeClassifier.java:38)
        at OpenCVTest.process(OpenCVTest.java:9)
        at OpenCVTest.main(OpenCVTest.java:16)

I have lines in there trying the single-string and the nullary constructors because both fail with the same error (but with different line numbers in CascadeClassifier.java).

I'm running 64-bit Java 8 update 40 (1.8.0_40-b25), same for my JDK and JRE, on Windows 7 SP1 x64.

I've included the call to load the DLL in a static block, so it should be loading once and exactly once before any constructors. I'm calling System.load() to the direct path instead of System.loadLibrary() to be 100% clear about what DLL I want to load and from where. I've tried mangling the path to the DLL, and Java gives me a different error that it can't find the DLL, so I know Java at least SEES opencv_java2411.dll. I am using corresponding versions of the JAR file with the bindings and the DLL (both 2.4.11 right now, though I've tried versions 2.4.10, 2.4.11, and 3.0.0 beta, all with this same error).

Any leads would be greatly appreciated. Thanks!

edit retag flag offensive close merge delete