OpenCV for Android: failed to load cascade classifier error
<p>This is the first time I use openCV library. I want to use it to detect the eyes. I have used the <code>FdActivity</code> code available in this tutorial: </p>

<p><a href="http://romanhosek.cz/android-eye-detection-updated-for-opencv-2-4-6/" rel="nofollow noreferrer">http://romanhosek.cz/android-eye-detection-updated-for-opencv-2-4-6/</a></p>

<p>The tutorial uses OpenCV 2.4.6, but I have downloaded version 3.1 in my project. Due to the version differences I have changed the lines that uses putText, rectangle, and circle to be imported from imgproc instead of Core. This is all what I've changed. I have added haarcascade_lefteye_2splits.xml and lbpcascade_frontalface.xml to the raw folder under res folder. </p>

<p>When running the app I get this error in the logcat: </p>

<pre><code>failed to load cascade classifier 
</code></pre>

<p>Which is only generated from these lines in if mJavaDetector or mJavaDetectorEye is empty: </p>

<pre><code> try {
                        // load cascade file from application resources
                        InputStream is = getResources().openRawResource(
                                R.raw.lbpcascade_frontalface);
                        File cascadeDir = getDir("cascade", Context.MODE_PRIVATE);
                        mCascadeFile = new File(cascadeDir,
                                "lbpcascade_frontalface.xml");
                        FileOutputStream os = new FileOutputStream(mCascadeFile);

                        byte[] buffer = new byte[4096];
                        int bytesRead;
                        while ((bytesRead = is.read(buffer)) != -1) {
                            os.write(buffer, 0, bytesRead);
                        }
                        is.close();
                        os.close();

                        // --------------------------------- load left eye
                        // classificator -----------------------------------
                        InputStream iser = getResources().openRawResource(
                                R.raw.haarcascade_lefteye_2splits);
                        File cascadeDirER = getDir("cascadeER",
                                Context.MODE_PRIVATE);
                        File cascadeFileER = new File(cascadeDirER,
                                "haarcascade_eye_right.xml");
                        FileOutputStream oser = new FileOutputStream(cascadeFileER);

                        byte[] bufferER = new byte[4096];
                        int bytesReadER;
                        while ((bytesReadER = iser.read(bufferER)) != -1) {
                            oser.write(bufferER, 0, bytesReadER);
                        }
                        iser.close();
                        oser.close();

                        mJavaDetector = new CascadeClassifier(
                                mCascadeFile.getAbsolutePath());
                        if (mJavaDetector.empty()) {
                            Log.e(TAG, "Failed to load cascade classifier");
                            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 classifier");
                            mJavaDetectorEye = null;
                        } else
                            Log.i(TAG, "Loaded cascade classifier from "
                                    + mCascadeFile.getAbsolutePath());



                        cascadeDir.delete();

                    } 
</code></pre>

<p>I guess the path to "haarcascade_eye_right.xml" is not correct, or the xml file doesn't exist, is this what is causing the error? </p>

<p>If yes, how can I have the xml file, and where exactly shall I store it? If no, what is causing the problem?</p>

<p>Note: I use Android Studio. </p>

<p>I'd appreciate any help in this regard, I've been trying for a while, but I couldn't solve it. </p>