资源简介
自己做人脸识别时写的小程序,space键快门,如果识别出人脸,画圈,再按w保存图片,按q放弃保存,图片大小92*112,保存路径和图片大小都可自行修改
代码片段和文件信息
#include “opencv2/opencv.hpp“
#include
#define mode_count 100
using namespace cv;
using namespace std;
int main()
{
int dst_count = 0;
char face_name[50] = {0};
CascadeClassifier face_cascade;
if(!face_cascade.load(“.//haarcascade_frontalface_alt.xml“))
{
cout << “Error loading“ << endl;
return -1;
};
VideoCapture v(0);
if(!v.isOpened())
{
cout << “camera open failed“ << endl;
return -1;
}
Mat src;
namedWindow(“src“);
while(1)
{
v >> src;
if(src.empty())
{
continue;
}
imshow(“src“ src);
char shutter = waitKey(1);
if(shutter == 32)
{
cvtColor(src src CV_BGR2GRAY);
Mat src_clone = src.clone();
equalizeHist(src src);
vector faces;
Mat faceROI;
face_cascade.detectMultiScale(src faces 1.1 2
评论
共有 条评论