Ask Your Question

Revision history [back]

with a bit modification as below i compiled and run without problem. ( opencv 2.4.10 , code-block)

"haarcascade_frontalface_alt2.xml" must be at the same directory

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>

using namespace std;
using namespace cv;

Mat detectFace(Mat src);

int main()
{
    VideoCapture cap(0);
    namedWindow("window1", 1);

    CascadeClassifier face_cascade("haarcascade_frontalface_alt2.xml");
    std::vector<Rect> faces;

    while (1)
    {
        Mat frame;
        cap >> frame;

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

        // Draw circles on the detected faces
        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);
        }

        imshow("window1", frame);
        // Press 'c' to escape
        if (waitKey(1) == 'c') break;
    }

    return 0;
}