ree*_*h11 2 c++ opencv face-detection
我目前正在研究人脸检测,然后是眼睛、嘴巴、鼻子和其他面部特征。对于上面的检测,我使用了haarcascade(正面脸、眼睛、右耳、左耳和嘴)。现在,如果脸部是正面的,一切正常和直。但是,如果面部处于侧视图中或旋转了,则效果不佳。对于侧视图,我使用了 lbscascade_profile.xml(它仅适用于脸部的右侧)。但是对于旋转的人脸,我无法检测到人脸。任何人都可以在上述上下文中帮助我。我在这里添加我的代码以便更好地理解。PS:提前致谢,请原谅我的幼稚问题(可能是因为我对编程非常陌生)。
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);
}
Run Code Online (Sandbox Code Playgroud)
那么 Flandmark将成为您的朋友!我最近经常使用它,结果证明它是头部姿势估计的成功工具,因此特别是在检测“旋转”面部时。它在角度范围内工作非常合理:倾斜(围绕平行于图像宽度的轴旋转)从 -30 到 +30 度,平移(围绕平行于图像高度的轴旋转)从 -45 到 +45 度。它也是一个强大的解决方案。