Current location - Education and Training Encyclopedia - Graduation thesis - Face recognition algorithm, how to find the part of the face from two pictures and compare whether two people are the same person.
Face recognition algorithm, how to find the part of the face from two pictures and compare whether two people are the same person.
In OPENCV. I used it in my senior year. After installation, Haar Cascade _ Frontalface _ default.xml will be fine in the DATA directory and haarcascades directory. This is the data of face recognition.

Please look up the usage according to this file name. I remember calling a function (C++) in OPENCV, and using this file name and the map as parameters, returning the location of the face in the map.

Hey hey, 50 minutes, here is my previous code, here is the part you need:

const char * cascadeFile = " Haar cascade _ frontal face _ alt . XML ";

const char * folder = " C:\ \ Program Files \ \ OpenCV \ \ data \ \ Haar cascades \ \ ";

char path[ 1024];

Sprintf (path, "%s%s", folder, cascade file);

CvHaarClassifierCascade * cascade =(CvHaarClassifierCascade *)cv load(path,0,0,0);

//Then cascade saved the CvHaarClassifierCascade it needed.

......

CVSEQ * Faces = CVHaardetectObjects (IMG, cascade, storage,

1. 1,2,CV_HAAR_DO_CANNY_PRUNING,

cvSize(source-& gt; getWidth()& gt; & gt7. Source-> getHeight()& gt; & gt7));

In this sentence, img is an IplImage *, and my own project comes from the camera. I guess you need to load the picture directly with opencv. Cascade is the sample data of the loaded OPENCV, and the storage is a space. I created it with cvmemstorage * storage = cvcreatememstorage (0), and I also used cvClearMemStorage(storage) before detecting the object. 1. 1 is scaling, 2 is detecting pixel size, CV_HAAR_DO_CANNY_PRUNING is comparison method, and OPENCV is a constant. Finally, the return value of cvSize is the minimum allowed face size. Every variable has an explanation.

Then face-> Only a few faces were found. Use cvGetSeqElem(faces, I) to get the data of each face, and take out (CvRect*). Remember TYPECAST, such as cvrect face1= * ((cvrect *) cvgetseqelem (faces, 0)). The CvRect thus obtained has four variables: face 1.x, face 1.y, face 1.width, face 1.height, which is the position of the face in the picture.