c++ - Eye detection in Oscar selfie -


i have perform eye detection on each of faces in famous oscar selfie image.i tried using haar casacades on faces since of them near-frontal, eye detection totally random , no eyes being recognized @ all.

enter image description here

i have have tried same haar cascade xml file eye detection on images single faces , worked fine.

what steps take correctly detect eyes?

the image used eye detection can downloaded here:

https://drive.google.com/file/d/0b3jt6shgpxo-d1plujg5eu5udw8/view?usp=sharing

below code have written face , eye detection. basic idea first detect face using viola jones algorithm , within each face, try detect eyes.

#include <opencv2/highgui/highgui.hpp> #include <cv.h> #include <opencv2/objdetect/objdetect.hpp> #include <vector>  using namespace cv; using namespace std;  int x,y,w,h;  int main(int argc, const char** argv) {     mat image = imread("oscarselfie.jpg",cv_load_image_unchanged);     mat gray_img;     cvtcolor(image, gray_img, cv_bgr2gray);      string facecascade_file = "haarcascade_frontalface_alt2.xml";     string eyecascade_file = "haarcascade_eye.xml";      cascadeclassifier facecascade;     cascadeclassifier eyecascade;         //cascade classifier class has method load classifier file     if( !facecascade.load( facecascade_file ) )         { cout<<"--(!)error loading\n"; return -1; };     //if returns zero, means error has occured in loading classifier      if( !eyecascade.load( eyecascade_file ) )         { cout<<"--(!)error loading\n"; return -1; };      equalizehist(gray_img, gray_img);     //increases contrast , make image more distingushable      /***** detecting faces in image *******/     vector<rect> faces;     vector<rect> eyes;     //rect class handling rectangle datatypes     facecascade.detectmultiscale(gray_img, faces, 1.1, 1,       0|cv_haar_scale_image, size(30, 30) );     //faces.size()-it return number of faces detected     for( int = 0; < faces.size(); i++ )     {         x = faces[i].x;         y = faces[i].y;         w = faces[i].width;         h = faces[i].height;         //point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );         //ellipse( image, center, size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, scalar( 255, 0, 255 ), 4, 8, 0 );         rectangle(image, cvpoint(x,y), cvpoint(x+w,y+h), cv_rgb(0,255,0), 2, 8 );          /******** detecting eyes ***********/     eyecascade.detectmultiscale(gray_img, eyes, 1.1, 50, 0|cv_haar_scale_image, size(30, 30) );      for(int j=0; j < eyes.size(); j++)     {         point center( faces[i].x + eyes[j].x + eyes[j].width*0.5, faces[i].y + eyes[j].y + eyes[j].height*0.5 );         int radius = cvround( (eyes[j].width + eyes[j].height)*0.25 );         circle( image, center, radius, scalar( 255, 0, 0 ), 4, 8, 0 );     } }  namedwindow("oscarselfie :)",  cv_window_autosize); imshow("oscarselfie :)", image); waitkey(0); destroywindow("pic");  return 0; 

} `

i following result facedetect.cpp (uses haarcascade_eye_tree_eyeglasses.xml)

don't expect find faces , eyes enter image description here

i tried dlib's face_landmark_detection_ex.cpp compare results enter image description here

dlib has feature gives aligned faces seen below

enter image description here


Comments