Ask Your Question
3

Android opencv eye detection

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

this post is marked as community wiki

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

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.

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
3

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

icedecker gravatar image

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.

edit flag offensive delete link more

Comments

thanks. I will check it.

karthi gravatar imagekarthi ( 2012-09-05 01:56:48 -0600 )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 gravatar imageelmiguelao ( 2012-09-28 09:09:55 -0600 )edit
-1

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

this post is marked as community wiki

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

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

edit flag offensive delete link more

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 gravatar imageAndrey Pavlenko ( 2012-09-28 10:01:23 -0600 )edit

Which camera qualities the camera need to detect the eyes esp. the pupils correctly? I have to develop a pupil tracker and synchronize it with a mouse pointer.

Nai gravatar imageNai ( 2015-04-08 03:20:11 -0600 )edit

*camera qualities: for example the camera resolution

Nai gravatar imageNai ( 2015-04-08 03:30:19 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 3,358 times

Last updated: Sep 28 '12