OpenCv 2.4.2代码解释 - 面部识别 [英] Opencv 2.4.2 Code Explaination-Face Recognition
问题描述
我已经参考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
它们使用的面向量如下
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?
推荐答案
检测到的面部作为一组矩形包围面部。如文档所述,输出矩形的向量,其中每个矩形包含检测到的对象。
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.
[初始x,初始y,宽度,高度]
。所以你可以通过(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屋!