So I want the face which is most prominent to be captured as an image file.
Here is the detection code below:
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);
}
如果检测到的面部的大小足以描述其突出程度(实际上不是),则由于faces
每个元素都是Rect
,您可以使用Rect::area()
作为度量。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.