0

I am trying to make a face detection software using OpenCV 2.3.0. While OpenCV 2.4 has the face recognizer class 2.3.0 is devoid of this feature. I checked the documentation and is specifies that the detectMultiScale function has the following declaration

void CascadeClassifier::detectMultiScale(const Mat& image, vector<Rect>& objects, double      
scaleFactor=1.1, int minNeighbors=3, int flags=0, Size minSize=Size())

Now I am giving the image, that is the camera feed, but don't know what to fill in vector block. Here is the code that I have written.

#include "cv.h"
#include "highgui.h"
#include <stdio.h>
#include<iostream>

using namespace cv;
using namespace std;

int main()
{
    std::vector<Rect> faces;
    VideoCapture cap(0);

    if(!cap.isOpened())
        cout<<"Camera is not connected"<<endl;
    cv::CascadeClassifier* cascade=0;
    if(cascade.empty())
        return -1;
    Mat edges;
    namedWindow("Camera Feed",1);
    for(;;)
    {
        Mat frame;
        cap >> frame;
        imshow("Camera Feed", frame);
        if(waitKey(10)==27)
            break;
        cascade.detectMultiScale(frame,faces);
    }
    return 0;
}

Question: How to proceed further?

SingerOfTheFall
  • 29,228
  • 8
  • 68
  • 105
praxmon
  • 5,009
  • 22
  • 74
  • 121
  • 2
    How should one answer your question, if you don't specify what you want to do? At this point you should have the vector faces and you can decide what to do with it's content. – Herr von Wurst Jul 05 '12 at 09:45
  • I basically want to make a face recognition program, if it detects the face in the incoming feed, it should encircle the face. I have the incoming feed, I don't know how to proceed further as no data is available for Opencv 2.3.0. – praxmon Jul 05 '12 at 10:02

2 Answers2

3

go through Docs OpenCV. check here for detail example

void detectAndDisplay( Mat frame )
{
  std::vector<Rect> faces;
  Mat frame_gray;

  cvtColor( frame, frame_gray, CV_BGR2GRAY );
  equalizeHist( frame_gray, frame_gray );

  //-- Detect faces
  face_cascade.detectMultiScale( frame_gray, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(30, 30) );

  for( int i = 0; i < faces.size(); i++ )
  {
    Point center( faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5 );
    ellipse( frame, center, Size( faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar( 255, 0, 255 ), 4, 8, 0 );

    Mat faceROI = frame_gray( faces[i] );
    std::vector<Rect> eyes;

    //-- In each face, detect eyes
    eyes_cascade.detectMultiScale( faceROI, eyes, 1.1, 2, 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( frame, center, radius, Scalar( 255, 0, 0 ), 4, 8, 0 );
     }
  }
  //-- Show what you got
  imshow( window_name, frame );
 }

hope this will help you

Nikson Kanti Paul
  • 3,394
  • 1
  • 35
  • 51
  • Thanks. The documentation for 2.3.2 is not loading. I've been waiting for 15 minutes. And how do I create my own haar cascade files? And is it necessary to create a new haar cascade file? – praxmon Jul 05 '12 at 13:55
  • hope you have already created your own cascade file...if not visit this blog http://mehebuba.blogspot.kr/ – MMH Aug 02 '13 at 04:43
0

Here is the 2.3 documentation http://www.opencv.org.cn/opencvdoc/2.3.2/html/index.html

Use the circle or rectangle function to draw the rectangles contained in the faces vector. Then use imshow to display the result.

Herr von Wurst
  • 2,571
  • 5
  • 32
  • 53