Ask Your Question
0

UnsatisfiedLinkError with CascadeClassifier

asked 2016-03-11 07:37:05 -0600

sd169048 gravatar image

updated 2016-03-11 09:04:23 -0600

berak gravatar image

I want to run a face detect program in java,and get :

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_1(Ljava/lang/String;)J

.How can I fix it?

public class DetectFace {
    public void Detect(){
        System.out.println("Running DetectFace...");
        System.out.println(getClass().getResource("lbpcascade_frontalface.xml").getPath());
//      CascadeClassifier faceDetector=new CascadeClassifier(getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1));
        String xmlfilePath=getClass().getResource("lbpcascade_frontalface.xml").getPath().substring(1);
        CascadeClassifier faceDetector = new CascadeClassifier(xmlfilePath);  

    }
}

Exception in thread "main" java.lang.UnsatisfiedLinkError: org.opencv.objdetect.CascadeClassifier.CascadeClassifier_1(Ljava/lang/String;)J
    at org.opencv.objdetect.CascadeClassifier.CascadeClassifier_1(Native Method)
    at org.opencv.objdetect.CascadeClassifier.<init>(CascadeClassifier.java:58)
    at faceDetect.DetectFace.Detect(DetectFace.java:18)
    at faceDetect.TestPro.main(TestPro.java:18)
edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
0

answered 2016-03-11 08:33:27 -0600

berak gravatar image

opencv is actually a c++ library (with additional java bindings). you forgot to load opencv_java.so/dll before using any native code.

public class DetectFace {
    static{ 
        System.loadLibrary(Core.NATIVE_LIBRARY_NAME); // load opencv_java
    }

    public void Detect(){
         ...
    }
}
edit flag offensive delete link more

Comments

Thanks for your answer! I have load opencv_java.so/dll in public static void main(String[] args),like this public static void main(String[] args) { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); new DetectFace().Detect(); } } and also try your advance,but the error is still exist.

sd169048 gravatar imagesd169048 ( 2016-03-11 19:29:42 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-03-11 07:37:05 -0600

Seen: 2,354 times

Last updated: Mar 11 '16