思想很简单,就是调用摄像头,获取图像帧,将图像帧放入opencv带的人脸识别库检测出窗口。最后使用滤波函数对检测窗口进行模糊操作。再拷贝回原图。完成
#include "opencv2/imgcodecs.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include "opencv2/photo.hpp"
#include <iostream>
#include <string>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/objdetect.hpp>
#include <opencv2\imgproc\types_c.h>
//#include <opencv2/gpu/gpu.hpp>
using namespace cv;
using namespace std;
string xmlPath = "E:/opencv_learn/opencv_test/haarcascade_frontalface_default.xml";
//xmlpath 字符串记录那个.xml文件的路径
void detectAndDisplay(Mat image);
int main(int argc, char** argv)
{
string path = "E:/opencv_learn/opencv_test/1.jpg";//以检测图片1.jpg为例
Mat image = imread(path, -1);
CascadeClassifier a; //创建脸部对象
if (!a.load(xmlPath)) //如果读取文件不出错,则检测人脸
{
cout << "无法加载xml文件" << endl;
return 0;
}
VideoCapture cam(0);
Mat frame;
cam.se