Here is the code that uses OPENCV to Haar face detection by reading the image on the hard disk.
Include header file
#include <opencv2/core/core.hpp>
#include "Cv.h"
#include "highgui.h"
int main ()
{
Const char* Cascade_name = "c:\\opencv249\\sources\\data\\haarcascades\\haarcascade_frontalface_alt2.xml";//classifier path, According to the actual fill
Static cvmemstorage* storage = 0;
static cvhaarclassifiercascade* cascade = 0;
Cascade = (cvhaarclassifiercascade*) cvload (cascade_name, 0, 0, 0);
Storage = cvcreatememstorage (0);
Iplimage *image = cvloadimage ("e:\\1.jpg");//read in the image, press the actual input
Cvseq* faces = cvhaardetectobjects (image, Cascade, storage, 1.1, 2, cv_haar_do_canny_pruning, cvsize (+));//haar Face Detection
int num_of_face = faces->total;//The number of faces that were detected
Cvscalar Color[1] = {255, 0, 0};//set Rectangle box color
for (int i = 1; i < Num_of_face + 1; i++)
{
cvrect* r = (cvrect*) Cvgetseqelem (faces, i); Gets the information for each face, the return type is a rectangle. I for face number, 0,1,2 ... Can be read in a loop.
Cvrectangle (Image, Cvpoint (r->x, R->y), Cvpoint (r->x + r->width, R->y + r->height), color[0], 3);// Draw a rectangular box
}
Cvnamedwindow ("Test", cv_window_autosize);//Create window, the second parameter cv_window_autosize represents the original size of the saved image
Cvshowimage ("Test", image);//Display picture
Cvwaitkey (0);//wait for operation
Cvreleaseimage (&image);//Release picture
Cvdestroywindow ("Test");//Destroy Window
return 0;
}
OPENCV-based face detection and save picture send: http://www.eyesourcecode.com/thread-41275-1-1.html
OpenCV Source: http://www.eyesourcecode.com/forum-OpenCV-1.html
OPENCV detecting human Face instance code