boundingRect()函数的使用方法

Calculates the up-right bounding rectangle of a point set.

C++: Rect boundingRect(InputArray points)

Parameters: points – Input 2D point set, stored in std::vector or Mat.    

注意(boundingRect读入的参数必须是vector或者Mat点集)


使用例程

for( size_t k = 0; k < contours.size(); k++ )

    {

    Rect ret1=boundingRect(Mat(contours[k]));//计算右上点集的边界矩形

    avgX = (ret1.x + ret1.x + ret1.width)/2; //运动物体的矩形的中点X位置

    avgY = (ret1.y + ret1.y + ret1.height)/2;//运动物体的矩形的中点Y位置

    cout<<"x:"<<avgX<<"y:"<<avgY<<endl;

     }


由上可以看出,boundingRect()的用法