检测到的面部作为面部周围的一组矩形返回。正如文档所说,输出是Vector of rectangles where each rectangle contains the detected object.
所以一个矩形由以下部分组成[ initial x, initial y, width, height ]
。所以你可以通过以下方式找到它的中心( x + width*0.5 , y + height*0.5 )
。这个中心对于椭圆来说也是一样的。
如果你想绘制矩形,请使用rectangle
功能。请参阅文档 http://docs.opencv.org/modules/core/doc/drawing_functions.html?highlight=rectangle#rectangle.
函数中的参数如下:
pt1 = ( x , y )
pt2 = ( x + width , y + height )
将画线椭圆更改为以下线:
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);
结果如下: