视频读取
#include
#include
using namespace std;
using namespace cv;
String Haar_fileName = "haarcascade_frontalface_alt.xml";//Haar
String LBP_fileName = "lbpcascade_frontalface.xml";//LBP
CascadeClassifier face_Haar_cascade;
CascadeClassifier face_LBP_cascade;
int main(int argc, char** argv)
{
if (!face_Haar_cascade.load(Haar_fileName))
{
cout << "Haar_cascade error" << endl;
return -1;
};
if (!face_LBP_cascade.load(LBP_fileName))
{
cout << "LBP_cascade error" << endl;
return -2;
};
VideoCapture capture;
Mat frame, gray;
vector faces;
capture.open("../path.mp4");//读入视频流
while(capture.read(frame))
{
cvtColor(frame, gray, COLOR_BGR2GRAY);//转灰度
equalizeHist(gray, gray);//直方图均衡化
//face_Haar_cascade.detectMultiScale(gray, faces, 1.2, 3, 0, Size(30, 30));//Haar级联分类器
face_LBP_cascade.detectMultiScale(gray, faces, 1.2, 3, 0, Size(30, 30));//LBP级联分类器
for (size_t i = 0; i < faces.size(); i++)
{
rectangle(frame, faces[i], Scalar(255, 0, 0), 2, 8, 0);
}
imshow("Haar_frame", frame);
char c = waitKey(50);
if (c == 27)
{
break;
}
}
//释放资源
capture.release();
waitKey(0);
return 0;
}
输出结果: