Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV CascadeClassifier error

i'm trying to do face detection through a webcam, but i got an error, cascadeclassifier error.

After do some testing, i found this line of code generate the error

CascadeClassifier face_cascade = new CascadeClassifier();

The error i got is

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 CamCapture.main(CamCapture.java:24)

Is anybody know how to solve this?


like image 354
Orochi Avatar asked Dec 27 '22 04:12

Orochi


2 Answers

finally i found the answer,

i should load the library before use the cascadeclassifier. so just put this code

System.loadLibrary(Core.NATIVE_LIBRARY_NAME);

before the cascadeclassifier.

like image 180
Orochi Avatar answered Dec 28 '22 19:12

Orochi


Try initialising CascadeClassifier objects in BaseLoaderCallBack. The OpenCV needs to load completely before initialising the CasCadeClassifier objects.

Place this in onCreate() or onResume():

if (!OpenCVLoader.initDebug())
    OpenCVLoader.initAsync(OpenCVLoader.OPENCV_VERSION, this, baseCallBack);
else
    baseCallBack.onManagerConnected(LoaderCallbackInterface.SUCCESS);

define baseCallBack as:

private BaseLoaderCallback baseCallBack = new BaseLoaderCallback(this) {
    @Override
    public void onManagerConnected(int status) {
        if (status == SUCCESS) {
            try {
                initClassifiers(); // initialise here
            } catch (IOException e) {
                e.printStackTrace();
            }
            Log.d("OpenCVLoad", "OpenCV Loaded");
        } else {
            super.onManagerConnected(status);
        }
    }
};
like image 22
Venu Sai Avatar answered Dec 28 '22 21:12

Venu Sai