所以我希望将最突出的脸部捕捉为图像文件。
以下是检测代码:
void detectAndDisplay(Mat frame)
{
std::vector<Rect> faces;
Mat gray;
cvtColor(frame, gray, CV_BGR2GRAY);
equalizeHist(gray,gray);
//find faces
face_cascade.detectMultiScale(gray, faces, 1.1, 2, 0 | CV_HAAR_SCALE_IMAGE, Size(30, 30));
for (size_t i = 0; i < faces.size(); i++)
{
Point center(faces[i].x + faces[i].width*0.5, faces[i].y + faces[i].height*0.5);
//draw around the face
ellipse(frame, center, Size(faces[i].width*0.5, faces[i].height*0.5), 0, 0, 360, Scalar(255, 255, 255), 4, 8, 0);
Mat faceROI = gray(faces[i]);
}
imshow(window_name, frame);
}