最简单的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得到。程序就是将检測到 的截图保存的人脸图像。我用这个程序来测试它们的速度训练效果。
给大家分享。
版权声明:本文博主原创文章。博客,未经同意不得转载。