Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Opencv 2.4.2 Code Explanation-Face Recognition

I have referred the documentation provided by OpenCV to make a face recognition program, it recognizes multiple faces and is working normally. In the documentation they have made ellipses to highlight the face. What I don't understand is how they have calculated the center of the ellipse which they have calculated as follows

for( int i = 0; i < faces.size(); i++ )
{
   Point center(faces[i].x+faces[i].width*0.5,faces[i].y+faces[i].height*0.5);
   //more code follows drawing the ellipse

The faces vector that they are using is produced as follows

face_cascade.detectMultiScale(frame_gray,faces,1.1,2,0|CV_HAAR_SCALE_IMAGE,cv::Size(30,30))

The documentation i.e. the program is given in the link

http://docs.opencv.org/doc/tutorials/objdetect/cascade_classifier/cascade_classifier.html

I want to know how they are calculating the center of the ellipse and if I want to draw a rectangle instead of a circle, what do I have to do?

like image 535
praxmon Avatar asked Jul 06 '12 04:07

praxmon


People also ask

How does LBPH algorithm work?

Given the above-mentioned parameters, LBPH works as follows; A data set is created by taking images with a camera or taking images that are saved, and then provisioning a unique identifier or name of the person in the image and then adding the images to a database.

What is DLIB Get_frontal_face_detector ()?

get_frontal_face_detector() returns dlib's HOG + Linear SVM face detector (Line 19). We then proceed to: Load the input image from disk. Resize the image (the smaller the image is, the faster HOG + Linear SVM will run) Convert the image from BGR to RGB channel ordering (dlib expects RGB images)


1 Answers

Detected faces are returned as a set of rectangles surrounding the faces. As documentation says, output is Vector of rectangles where each rectangle contains the detected object.

So one rectangle is comprised of [ initial x, initial y, width, height ]. So you can find its center by ( x + width*0.5 , y + height*0.5 ). This center is same for the ellipse also.

If you want to draw rectangles, use rectangle function. See the Documentation.

Arguments in the function will be as follows :

pt1 = ( x , y )

pt2 = ( x + width , y + height )

Change the line drawing ellipse to following line :

rectangle(frame,Point (faces[i].x,faces[i].y),Point (faces[i].x+faces[i].width, faces[i].y+faces[i].height),Scalar(255,0,255),4,8,0);

It gives the result as follows :

enter image description here

like image 162
Abid Rahman K Avatar answered Sep 22 '22 00:09

Abid Rahman K