1
我正在從視頻中進行人臉檢測。所以我寫了一個小代碼來檢測臉部。我們如何更準確地檢測臉部
#include<opencv2/objdetect/objdetect.hpp>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include <iostream>
#include <stdio.h>
#include<cv.h>
using namespace std;
using namespace cv;
CvCapture *capture=cvCaptureFromFile("foot.mp4");
double min_face_size=30;
double max_face_size=400;
Mat detectFace(Mat src);
int main()
{
namedWindow("window1", 1);
while(1)
{
Mat frame,frame1;
frame1=cvQueryFrame(capture);;
frame=detectFace(frame1);
imshow("window1", frame);
if(waitKey(1) == 'c') break;
}
waitKey(0);
return 0;
}
Mat detectFace(Mat image)
{
CascadeClassifier face_cascade("haarcascade_frontalface_alt2.xml");
CvPoint ul,lr;
std::vector<Rect> faces;
face_cascade.detectMultiScale(image, faces, 1.1, 2, 0|CV_HAAR_SCALE_IMAGE, Size(min_face_size, min_face_size),Size(max_face_size, max_face_size));
for(int i = 0; i < faces.size(); i++)
{
min_face_size = faces[i].width*0.8;
max_face_size = faces[i].width*1.2;
ul.x=faces[i].x;
ul.y=faces[i].y;
lr.x=faces[i].x + faces[i].width;
lr.y=faces[i].y + faces[i].height;
rectangle(image,ul,lr,CV_RGB(1,255,0),3,8,0);
}
return image;
}
我拍了一張包含小臉和大臉的人臉檢測視頻。我的問題是使用我的代碼,它只能檢測到小臉,並顯示一些不需要的檢測。
我需要檢測視頻中的小臉和大臉。我該怎麼做? 比例因子有問題嗎?
請幫我理解這個問題。
我增加了'max_face_size'的值。但當時它只能檢測到大圖像。我想要檢測小圖像和大圖像。 – user3349808