接触Opencv一段时间了,最近导师一直让我看人脸识别相关的东西,看了这么多大牛写的人脸识别、追踪,一直没有自己动手写过,花了点时间写了一个简单的,单目标下能识别到人脸没问题,多目标下目前没测试,理论上应该可以(多目标识别已测试,识别成功)。
haar classifier cascade是opencv下自带的人脸检测的级联分类器,支持haar特征,新版本的CascadeClassifier好像支持LBP特征,没试过。
HaarDetect.h
#ifndef HAARDETECT_H
#define HAARDETECT_H
#include <opencv2\highgui\highgui.hpp>
#include <opencv2\imgproc\imgproc.hpp>
#include <opencv2\objdetect\objdetect.hpp>
using namespace std;
using namespace cv;
CvHaarClassifierCascade* Load_Haar_Cascade();
void detectFace(IplImage* frame,CvHaarClassifierCascade *faceCascade,CvRect *faceRect,int &count);
#endif
HaarDetect.cpp
#include "HaarDetect.h"
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
CvHaarClassifierCasc