google adsense 728x90 display ad

Android Studio OpenCV CascadeClassifier can't load

Hi everyone.

I'm developing an android application using OpenCV(https://opencv.org/) in Android Studio.

Since I'm a newbie to OpenCV I followed a guide from http://romanhosek.cz/android-eye-detection-updated-for-opencv-2-4-6/.

However I faced some issue related to CascadeClassifier.
Even though the argument in new CascaseClassifier() means correct exist file mJavaDetector.empty() and mJavaDetectorEye.empty() returned true.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
if (mJavaDetector.empty()) {
    Log.e(TAG, "Failed to load cascade classifier1");
    mJavaDetector = null;
else
    Log.i(TAG, "Loaded cascade classifier from "
            + mCascadeFile.getAbsolutePath());
 
mJavaDetectorEye = new CascadeClassifier(cascadeFileER.getAbsolutePath());
if (mJavaDetectorEye.empty()) {
    Log.e(TAG, "Failed to load cascade classifier2");
    mJavaDetectorEye = null;
else
    Log.i(TAG, "Loaded cascade classifier from "
            + cascadeFileER.getAbsolutePath());

How to fix this issue is simple. Just add below code by the blue shaded area.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
mJavaDetector.load(mCascadeFile.getAbsolutePath());
if (mJavaDetector.empty()) {
    Log.e(TAG, "Failed to load cascade classifier1");
    mJavaDetector = null;
else
    Log.i(TAG, "Loaded cascade classifier from "
            + mCascadeFile.getAbsolutePath());
 
mJavaDetectorEye = new CascadeClassifier(cascadeFileER.getAbsolutePath());
mJavaDetectorEye.load(cascadeFileER.getAbsolutePath());
if (mJavaDetectorEye.empty()) {
    Log.e(TAG, "Failed to load cascade classifier2");
    mJavaDetectorEye = null;
else
    Log.i(TAG, "Loaded cascade classifier from "
            + cascadeFileER.getAbsolutePath());

No comments:

Powered by Blogger.