简体   繁体   English

使用opencv C ++进行面部定向

[英]orientation of face using opencv C++

I am currently working on face detection and thereafter eyes, mouth, nose and other facial features.For above detection I have used haarcascade( frontal face, eyes, right_ear, left_ear and mouth) .Now, everything works perfectly, if the face is frontal and straight. 我目前正在进行面部检测,然后再进行眼睛,嘴巴,鼻子和其他面部特征的检测。对于上面的检测,我使用了haarcascade(正面,眼睛,右耳,左耳和嘴巴) 。和直。 But I am not getting good result if the face is in side view or it is rotated. 但是如果脸部处于侧面或旋转状态,我的效果将不佳。 For side view, I have used lbscascade_profile.xml( it works only for right side of face). 对于侧视图,我使用了lbscascade_profile.xml(它仅适用于脸部右侧)。 But for rotated face, I am not able to detect face.Can anyone help me out in above context.I am adding my code here for better understanding. 但是对于旋转的脸部,我无法检测到脸部,任何人都可以在上述情况下为我提供帮助。我在此处添加代码以更好地理解。 PS : Thanks in advance and Pardon me for childish question( it might be because I am very new to programming). 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);
}

Flandmark will be your friend, then! 那么,Flandmark将成为您的朋友! I've been using it recently quite often, and it turned out to be a successful tool in head pose estimation hence particular in detecting "rotated" face. 我最近经常使用它,事实证明它是成功进行头部姿势估计的工具,因此特别适用于检测“旋转”的面部。 It works quite reasonable in range of angles: tilt (rotation around axis parallel to image's width) from -30 to +30 degrees, pan (rotation around axis parallel to image's height) from -45 to +45 degrees. 它的角度范围非常合理:倾斜(围绕与图像宽度平行的轴旋转)从-30度到+30度,平移(围绕与图像高度平行的轴旋转)从-45度到+45度。 Also it is a robust solution. 这也是一个可靠的解决方案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM