【发布时间】:2014-09-01 17:21:23
【问题描述】:
我正在尝试一个非常简单的程序来检测网络摄像头提要中的面孔。我注意到当我的脸位于框架的中心时,可以很好地检测到这些脸。每当我向两侧移动一点时,人脸检测器要么完全错过我的脸,要么没有检测到。 这种偏见是因为我使用函数的方式(附加代码)还是 HAAR 分类器中的固有偏见? 请注意,在任何一种情况下(我的脸在框架的大致中心或我的脸在边界附近的某个地方),我的脸是完全可见的,即侧面轮廓/或脸部切割。
//A live face detector Program. Takes feed from the camera and detects face in the given frame
#include<opencv2/opencv.hpp>
#include<iostream>
#include<vector>
#include"opencv2/video/video.hpp"
using namespace cv;
using namespace std;
int main(){
cv::Mat frame;
cv::VideoCapture cap(0);
cv::namedWindow("Frame");
do{
cap >> frame;
Rect r1,r2;
vector<Rect> faces1,faces2;
CascadeClassifier cascade1;
CascadeClassifier cascade2;
//cascade1.load("C:/opencv2.4.9/sources/data/lbpcascades/lbpcascade_frontalface.xml");
cascade1.load("C:/opencv2.4.9/sources/data/haarcascades/haarcascade_frontalface_alt2.xml");
cascade2.load("C:/opencv2.4.9/sources/data/lbpcascades/lbpcascade_profileface.xml");
cascade1.detectMultiScale(frame, faces1,1.05, 6, CV_HAAR_FIND_BIGGEST_OBJECT, Size(0, 0));
cascade2.detectMultiScale(frame, faces2,1.05, 6, CV_HAAR_FIND_BIGGEST_OBJECT, Size(0, 0));
if (faces1.size()!=0){
cout << "face1 found";
r1 = faces1[0];
}
if (faces2.size()!=0){
cout << "face2 found";
r2 = faces2[0];
}
rectangle(frame, Point(r1.y,r1.x), Point(r1.y+r1.height,r1.x+r1.width), Scalar(0,255,0),2, 8);
rectangle(frame, Point(r2.y,r2.x), Point(r2.y+r2.height,r2.x+r2.width), Scalar(255,0,0),2, 8);
imshow("Frame",frame);
}while(waitKey(30) < 0);
cap.release();
return 0;
}
【问题讨论】:
-
我建议它与您的训练规模有关,始终训练尽可能小。如果您在大图像上进行训练,您将无法检测到较小(或更远)的人脸
-
我使用的是openCV打包的xml文件。我没有接受任何训练。此代码仅用于检测人脸。无法识别。
-
在documentation 中,他们发现不在中心的面孔。但他们正在使用“haarcascade_frontalface_alt.xml”。
-
你的方法是只找到一张脸还是可以找到更多,只要它们位于框架的中心?
-
@powder: 我写的代码总是只检测一次。
标签: c++ opencv face-detection