实现脸部打马赛克

#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include 
#include 


using namespace std;
using namespace cv;

String face_cascade_name = "D:\\opencv\\sources\\data\\lbpcascades\\lbpcascade_frontalface.xml"; //根据自己的实际情况设置
String eyes_cascade_name = "D:\\opencv\\sources\\data\\haarcascades\\haarcascade_eye_tree_eyeglasses.xml";
CascadeClassifier face_cascade;
CascadeClassifier eyes_cascade;

int main(int argc, const char** argv)
{
	Mat frame;
	face_cascade.load(face_cascade_name);
	if (!face_cascade.load(face_cascade_name))
	{
		printf("--(!)Error loading\n"); return -1;
	};
	//frame = imread("0.jpg");
	VideoCapture cap;
	cap.open(0);
	vector faces;  //创建一个容器保存检测出来的脸
	Mat gray;
	for (;;)
	{
		cap.read(frame);
		cvtColor(frame, gray, CV_BGR2GRAY);
		equalizeHist(gray, gray);
		face_cascade.detectMultiScale(gray, faces, 1.1, 3, 0, Size(20, 20));
		for (int i = 0; i < faces.size(); i++)
		{
			//rectangle(frame, faces[i], Scalar(0, 0, 255), 2, 8); //画出脸部矩形
			Mat faceROI =gray(faces[i]);
			Mat faceOrg = frame(faces[i]);
			blur(faceOrg, faceOrg, Size(25, 25));
		}
		imshow("src", frame);
		if (waitKey(5) >= 0)
			break;

	}

	return 0;
}

你可能感兴趣的:(图像识别)