2016-03-26 9 views
1

有名なオスカーセルフイメージの各面で目の検出を実行する必要があります。ほとんどのセルは正面に近いのでHaar Casacadesを使ってみましたが、目の検出は完全にランダムです目は全く認識されていません。オスカーセルフでの目の検出

enter image description here

私は、単一の顔の画像上の目検出のための同じハールカスケードxmlファイルを試してみまして、それがうまく働きました。

目を正しく検出するにはどのような手順が必要ですか?

私は目の検出のために使用される画像は、こちらからダウンロードできます。以下は

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

は、私が顔や目検出のために書かれているコードです。基本的なアイデアは、私は最初にビオラのジョーンズのアルゴリズムを使用して顔を検出し、各顔の中で、私は目を検出しようとしています。

#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; 

} `

+0

車輪を改革する必要がなく、OpenCVの参照[サンプル](https://github.com/Itseez/opencv/blob/master/samples/cpp/facedetect .cpp)と[チュートリアル](https://github.com/Itseez/opencv/blob/master/samples/cpp/tutorial_code/objectDetection/objectDetection.cpp) – sturkmen

+0

ちょっとsturkmen、私はすでにチュートリアルとサンプルを使っていますが私は、オクルージョンのためにすべての顔を検出することができないと私の目の検出はちょうどひどいです、それは1つの目だけではなく、それらのペアを検出しません。 –

答えて

1

私はfacedetect.cppと、次の結果を得る(haarcascade_eye_tree_eyeglasses.xmlを使用しています)

は、私はまた、DLIBのface_landmark_detection_ex.cppを試みたすべての顔と目 enter image description here

を見つけることを期待しないでください結果を比較する enter image description here

DLIBは、あなたが顔ランドマーク検出のためのCLM-frameworkを使用したい場合があり

enter image description here

+1

ちょっとsturkmen、私は間違いを持っ​​ています。私は各顔ではなく画像全体で目の検出を行っていました。ヘルプとサンプルコードをありがとう。 :) –

0

の下に見られるように整列顔を与え、余分な機能を持っています。私の経験ではCLMフレームワークのパフォーマンスは満足できるものです。

作用におけるシステムのいくつかの例:http://youtu.be/V7rV0uy7heQ

+0

こんにちはGiray、別のライブラリを提案していただきありがとうございます。しかし、私はOpenCVを使ってより良い方法を探していました。 –

関連する問題