人脸检测


#include   
#include 
using namespace cv;
using namespace std;

int main()
{
    CascadeClassifier faceDetector;
    std::string faceCascadeFilename = "haarcascade_frontalface_alt.xml";
    faceDetector.load(faceCascadeFilename);
    VideoCapture camera(0);

    for (Mat camerFrame;waitKey(1)!=27;)
    {
        camera >> camerFrame;
        Mat displayedFrame(camerFrame.size(), CV_8UC3);
        Mat gray;
        Mat equalizedImg;

        cvtColor(camerFrame, gray, CV_BGR2GRAY);
        equalizeHist(gray, equalizedImg);

        std::vector faces;
        faceDetector.detectMultiScale(equalizedImg, faces, 1.1f, 4, CASCADE_FIND_BIGGEST_OBJECT | CASCADE_DO_ROUGH_SEARCH, Size(30, 30));

        for (vector::const_iterator iter = faces.begin(); iter != faces.end(); iter++)
        {
            rectangle(camerFrame, *iter, Scalar(0, 0, 255), 2, 8); //画出脸部矩形
        }


        imshow("原图", camerFrame);
    }
    return 0;
}

你可能感兴趣的:(人脸检测)