Opencv 2.4.2 Code Explanation-Face Recognition

我的梦境 提交于 2019-12-03 07:51:30

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 :

By the way, OpenCV 2.4.2 has face recognition included. Here is a tutorial and full source code sample for combining face detection (with cv::CascadeClassifier) and face recognition (with cv::FaceRecognizer):

Since you asked for face recognition. It also shows how to do face detection, so it may be interesting as well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!