Ask Your Question
3

Android opencv eye detection

asked 2012-09-01 01:05:04 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

updated 2012-09-01 01:05:04 -0500

karthi gravatar image karthi
121 2 12

I am using android "opencv samples - face detection" to detect the face. It is working good. Now I want to include "eye detection" with "face detection". Is it possible? if yes can anyone give me some samples to detect the eye.

delete close flag offensive retag edit

2 Answers

Sort by ยป oldest newest most voted
3

answered 2012-09-04 08:14:56 -0500

icedecker gravatar image icedecker
473 3 8 16

I think that is possible. You only need to load another cascade (nested cascade) and use the detectMultiScale in the ROI detected by the face cascade. It would be something like as:

CascadeClassifier cascade, nestedCascade;
// make the necessary operations to load the cascades
cascade.detectMultiScale(...);

for( // iterate all the ROIs detected by cascade.detect ){
           nestedCascade.detectMultiScale(...);
}

Take a look at the facedetect.cpp example in the c samples.

link delete flag offensive edit

Comments

thanks. I will check it.

karthi ( 2012-09-05 01:56:48 -0500 )edit

when I tried setImageROI for face detection, with this same idea, I noticed that the detect function ignores the ROI, back in openCV 2.3.1 or so. Just a word of caution :)

elmiguelao ( 2012-09-28 09:09:55 -0500 )edit
-1

answered 2012-09-28 08:32:42 -0500

this post is marked as community wiki

This post is a wiki. Anyone with karma >50 is welcome to improve it.

updated 2012-09-28 09:59:22 -0500

Andrey Pavlenko gravatar image Andrey Pavlenko
2270 3 15 36

hi, i wanna do the same thing using the sample facedetection of opencv 2.4.2. my problem is when i tried to load the two cascade classifier files it doesn't work for the second file.this is what i did:

try {
        InputStream is = context.getResources().openRawResource(R.raw.haarcascade_profileface);
        File cascadeDir = context.getDir("cascade", Context.MODE_PRIVATE);
        mCascadeFile = new File(cascadeDir, "haarcascade_profileface.xml");
        mCascadeFileeyes = new File(cascadeDir, "haarcascade_eye_tree_eyeglasses.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();
        mJavaDetector = new CascadeClassifier(mCascadeFile.getAbsolutePath());
        mJavaDetectoreye=new CascadeClassifier(mCascadeFileeyes.getAbsolutePath());
        //mJavaDetectoreye.load("haarcascade_eye_tree_eyeglasses.xml");
        if (mJavaDetector.empty()) {
            Log.e(TAG, "Failed to load cascade classifier");
            mJavaDetector = null;
        } else
            Log.i(TAG, "Loaded cascade classifier from " + mCascadeFile.getAbsolutePath());
        if (mJavaDetectoreye.empty()) {
            Log.e(TAG, "Failed to load cascade classifiereye");
            mJavaDetectoreye = null;
        } else
            Log.i(TAG, "Loaded cascade classifier from " + mCascadeFileeyes.getAbsolutePath());

when i run the project it crashed and show in the logcat error :Failed to load cascadeclassifiereye =>it seams to be not loading the eyes classifier file So can i load the 2 files ? and how can i detect eyes and face ?is there any way to do it? please i really need help to solve this problem as soon as possible. thanks in advance

link delete flag offensive edit

Comments

you need to add the similar code for your cascade like existed for the face one:

<code> 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(); </code>

Andrey Pavlenko ( 2012-09-28 10:01:23 -0500 )edit

Login/Signup to Answer

Question tools

Follow
1 follower

subscribe to rss feed

Stats

Asked: 2012-09-01 01:05:04 -0500

Seen: 1,111 times

Last updated: Sep 28 '12