【问题标题】:orientation of face using opencv C++使用opencv C ++的人脸方向
【发布时间】: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


【解决方案1】:

Flandmark 将成为你的朋友,那么!我最近经常使用它,结果证明它是一个成功的头部姿势估计工具,因此特别适用于检测“旋转”的脸。它在角度范围内非常合理:倾斜(围绕平行于图像宽度的轴旋转)从 -30 到 +30 度,平移(围绕平行于图像高度的轴旋转)从 -45 到 +45 度。它也是一个强大的解决方案。

【讨论】:

猜你喜欢
  • 2014-01-31
  • 2011-04-26
  • 2017-12-24
  • 2019-09-26
  • 2015-06-17
  • 1970-01-01
  • 1970-01-01
  • 2015-12-11
  • 2018-11-25
相关资源
最近更新 更多