一、效果展示
二、代码如下
#include <iostream>
#include <opencv2/opencv.hpp>
#include "opencv2/imgproc/imgproc_c.h"
using namespace cv;
using namespace std;
//人脸识别
void datectFace(Mat& frame, CascadeClassifier cascade, double scale)
{
//灰度化处理 节省内存
Mat gray;
cvtColor(frame, gray, COLOR_RGB2GRAY);
//级联分类器比帧差法还更慢,因此,需要再将灰度图大小压缩一半左右 行列压缩
Mat smalling(cvRound(frame.rows / scale), cvRound(frame.cols / scale), CV_8UC1);
//按存储大小计算 压缩方式采用线性压缩
resize(gray, smalling, smalling.size(), 0, 0, INTER_LINEAR);
//直方图均值化 让灰度图经过直方图函数处理 黑白分明
equalizeHist(smalling, smalling);
//imshow("smalling",smalling);
//调用级联分类器进行模型匹配并进行框选识别 使用模型去进行每一个像素点的遍历
vector<Rect>faces;
//使用CV_HAAR_SCALE_IMAGE算法 图像甄别
cascade.detectMultiScale(smalling, faces, 1.1, 2, 0 | CASCADE_SCALE_IMA