【发布时间】:2014-07-22 08:53:42
【问题描述】:
我目前正在研究面部检测,然后是眼睛、嘴巴、鼻子和其他面部特征。对于上述检测,我使用了 haarcascade(正面面部、眼睛、右耳、左耳和嘴巴)。现在,如果脸部正面且笔直,一切都会完美无缺。但是如果脸部在侧视图或旋转,我不会得到好的结果。对于侧视图,我使用了 lbscascade_profile.xml(它仅适用于脸部右侧)。但是对于旋转的脸,我无法检测到脸。任何人都可以在上述情况下帮助我。我在这里添加我的代码以便更好地理解。 P.S:提前感谢并原谅我提出幼稚的问题(可能是因为我对编程很陌生)。
void detectAndDisplay( Mat frame)
{
// create a vector array to store the face found
std::vector<Rect> faces;
Mat frame_gray;
bool mirror_image = false;
// convert the frame image into gray image file
cvtColor( frame, frame_gray, CV_BGR2GRAY);
//equalize the gray image file
equalizeHist( frame_gray, frame_gray);
//find the frontal faces and store them in vector array
face_cascade1.detectMultiScale(frame_gray,
faces,
1.1, 2,
0|CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT,
Size(40, 40),
Size(200, 200));
// find the right side face and store that in the face vector
if(!(faces.size()))
{
profileface_cascade.detectMultiScale( frame_gray,
faces,
1.2, 3,
0|CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT,
Size(40, 40),
Size(200, 200));
}
// find whether left face exist or not by flipping the frame and checking through lbsprofile
if(!faces.size())
{
cv::flip(frame_gray, frame_gray, 1);
profileface_cascade.detectMultiScale( frame_gray,
faces,
1.2, 3,
0|CV_HAAR_SCALE_IMAGE|CV_HAAR_FIND_BIGGEST_OBJECT,
Size(40, 40),
Size(200, 200));
mirror_image = true;
}
// if the frame is not flipped then the it could be directly drawn into frame
if(mirror_image and faces.size())
{
// flip the frame
cv::flip(frame_gray, frame_gray, 1);
}
if(faces.size())
{
//draw rectangle for the faces detected
rectangle(frame, faces[0], cvScalar(0, 255, 0, 0), 1, 8, 0);
}
// check whether any face is present in frame or not
else
image_not_found++;
imshow("Face Detection", frame);
}
【问题讨论】:
-
IMO 太宽泛了。您表现出零努力,似乎在询问代码。目前,您似乎希望有人为您编写一段通用代码。也许你可以用简单的具体例子来描述你的问题。
标签: c++ opencv face-detection