This is the first time I use the openCV library. I want to use it for eye detection. I used the FdActivity code available in this tutorial:
http://romanhosek.cz/android-eye-detection-updated-for-opencv-2-4-6/
The tutorial uses OpenCV 2.4.6, but I downloaded version 3.1 into my project. Due to the differences in version, I changed the lines that use putText, the rectangle and the circle to import from imgproc instead of Core. That is all that I have changed. I added haarcascade_lefteye_2splits.xml and lbpcascade_frontalface.xml to the raw folder under the res folder.
When starting the application, I get this error in logcat:
failed to load cascade classifier
which is generated only from these lines if mJavaDetector or mJavaDetectorEye is empty:
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(); }
I assume that the path to "haarcascade_eye_right.xml" is incorrect or the xml file does not exist, is this the cause of the error?
If so, how can I get the xml file and where exactly is it stored? If not, what causes the problem?
Note. I am using Android Studio.
I would be grateful for any help in this regard, I tried for some time, but I could not solve it.