Opencv 2.4.2代码说明-人脸识别 [英] Opencv 2.4.2 Code Explanation-Face Recognition

查看:117
本文介绍了Opencv 2.4.2代码说明-人脸识别的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我参考了OpenCV提供的文档来制作人脸识别程序,该程序可以识别多张人脸并且可以正常工作.在文档中,他们制作了椭圆形以突出显示脸部.我不明白的是他们是如何计算椭圆的中心的,它们的计算方法如下

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))

文档(即程序)在链接

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?

推荐答案

检测到的面将作为围绕这些面的一组矩形返回.如文档所述,输出为Vector of rectangles where each rectangle contains the detected object.

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.

因此,一个矩形由[ initial x, initial y, width, height ]组成.因此,您可以通过( x + width*0.5 , y + height*0.5 )找到其中心.该中心对于椭圆也相同.

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.

如果要绘制矩形,请使用rectangle函数.请参阅文档.

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

函数中的参数如下:

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);

结果如下:

这篇关于Opencv 2.4.2代码说明-人脸识别的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆