眼睛检测在奥斯卡自拍照 [英] Eye detection in Oscar selfie

查看:310
本文介绍了眼睛检测在奥斯卡自拍照的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须对着名的奥斯卡自拍图像中的每一张脸进行眼睛检测。我尝试在脸上使用Haar Casacades,因为大多数人都是接近正面,但眼睛检测完全随机,没有眼睛





我已经尝试过



我可以采取什么步骤来正确检测眼睛?



我用于眼睛检测的图片可以从这里下载:





我也尝试过dlib的 face_landmark_detection_ex.cpp 比较结果



dlib有一个额外的功能, p>


I have to perform eye detection on each of the faces in the famous Oscar selfie image.I tried using Haar Casacades on the faces since most of them are near-frontal, but the eye detection is totally random and no eyes are being recognized at all.

I have have tried the same haar cascade xml file for eye detection on images with single faces and it worked fine.

What steps could I take to correctly detect the eyes?

The image I used for eye detection can be downloaded from here:

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

Below is the code I have written for face and eye detection. Basic idea is I first detect the face using viola jones algorithm and within each face, I try to detect the 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 is a class which has a method to load the classifier from file
    if( !faceCascade.load( faceCascade_file ) )
        { cout<<"--(!)Error loading\n"; return -1; };
    //If it returns zero, it means an error has occured in loading the classifier

    if( !eyeCascade.load( eyeCascade_file ) )
        { cout<<"--(!)Error loading\n"; return -1; };

    equalizeHist(gray_img, gray_img);
    //Increases contrast and make image more distingushable

    /***** Detecting Faces in Image *******/
    vector<Rect> faces;
    vector<Rect> eyes;
    //Rect is a class handling the rectangle datatypes
    faceCascade.detectMultiScale(gray_img, faces, 1.1, 1,       0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );
    //faces.size()-it will return number of faces detected
    for( int i = 0; i < 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 get the following result with facedetect.cpp (uses haarcascade_eye_tree_eyeglasses.xml)

don't expect to find all faces and eyes

i also tried dlib's face_landmark_detection_ex.cpp to compare results

dlib has an extra feature that gives you aligned faces like seen below

这篇关于眼睛检测在奥斯卡自拍照的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆