资源简介
ViolaJones是人脸识别中效率最高的,在OpenCV中对应的库文件为cvHaarDetectObjects, 本文件为自己写的识别代码,调用该库函数
配置好OpenCV之后可以使用
代码片段和文件信息
// opencvtest.cpp : entrnce of the program
#include “stdafx.h“
#include
#include
using namespace std;
using namespace cv;
int main(int argc char** argv)
{
// Declarations
IplImage * pInpImg =0; //picture that waiting for detecting
CvHaarClassifierCascade * pCascade = 0; //face detector
CvMemStorage * pStorage = 0; // expandable memory buffer
CvSeq * pFaceRectSeq; // list of detected faces
// initializations
pInpImg = cvLoadImage(“zhangxiaokang.jpg“); //loading picture
pStorage = cvCreateMemStorage(0);
pCascade = (CvHaarClassifierCascade *)cvLoad
(“D:\\opencv\\data\\haarcascades\\haarcascade_frontalface_alt2.xml“ //classifier provided by OpenCV
0 0 0 );
// validate that everything initialized properly
if( !pInpImg || !pStorage || !pCascade )
{
printf(“Initialization failed: %s\n“
(!pInpImg)? “can‘t load image file“ :
(!pCascade)? “can‘t load haar-cascade -- “
“make sure path is correct“ :
“unable to allocate memory for data storage“ argv[1]);
exit(-1);
}
//to have some pre-process of the picture
IplImage* gray=cvCreateImage(cvSize(pInpImg->widthpInpImg->height)81); //creat an image as big as the loaded one
IplImage* small_img=cvCreateImage(cvSize(cvRound(pInpImg->width/1.3)cvRound(pInpImg->height/1.3))81); //creat
评论
共有 条评论