首页 > 代码库 > 最简单的ADABOOST人脸检测例程。COPY运行,前提是你配置好OpenCV环境

最简单的ADABOOST人脸检测例程。COPY运行,前提是你配置好OpenCV环境

#include "cv.h"
#include "highgui.h"
#include "stdio.h"

void main()
{
	IplImage* img = NULL;
	IplImage* cutImg = NULL;
	CvMemStorage* storage = cvCreateMemStorage(0);
	//CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad("data.xml", 0, 0, 0);
	CvHaarClassifierCascade* cascade = (CvHaarClassifierCascade*)cvLoad("haarcascade_frontalface_alt2.xml", 0, 0, 0);
	CvSeq* faces;
	char save_path[100];
	char path[100];
	int j;
	int index = -1;
	for (int i = 5 ; i <= 100; i++)
	{
	
		sprintf(path,"..\\20140622jiezhen\\%d.bmp", i);
		sprintf(save_path,"..\\GABCUT\\%d.bmp", i);
		img = cvLoadImage(path, 0);
	
		
		faces = cvHaarDetectObjects(img, cascade,  storage, 1.2, 2, 0, cvSize(25,25) );
		if (faces->total == 0)
			continue;
		cvSetImageROI(img, *((CvRect*)cvGetSeqElem( faces, 0))); 
		cvSaveImage(save_path, img);    
        cvResetImageROI(img);   
		
	}
	

	
}

这里用的xml文件是openCV已经训练好的人脸参数,可以在OpenCV安装目录下搜索*.xml得到。程序就是将检测到 的人脸图像截图保存。我用这个程序来快速检测自己训练的效果。分享给大家。

最简单的ADABOOST人脸检测例程。COPY运行,前提是你配置好OpenCV环境