你好StackOverflowers计算包围盒
领域我已经创建了一个应用程序,使用分段INRANGE功能的预定义颜色的基础上的图像。然后,我围绕检测到的物体绘制边界框。
我在这里的问题是,我该如何确定区域的属性,如:面积,大小,高度,并用,中心点。
在这里,我放在一个画面倾印.....
我应该怎样的方法来获取这些边框或任何其他包围盒即得到淹没区域特性..... ..?
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours(mBlur, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0));
/// Approximate contours to polygons + get bounding rects and circles
vector<vector<Point> > contours_poly(contours.size());
vector<Rect> boundRect(contours.size());
vector<Point2f>center(contours.size());
vector<float>radius(contours.size());
for(int i = 0; i < contours.size(); i++)
{ approxPolyDP(Mat(contours[i]), contours_poly[i], 3, true);
boundRect[i] = boundingRect(Mat(contours_poly[i]));
}
/// Draw polygonal contour + bonding rects
Mat drawing = Mat::zeros(range_out.size(), CV_8UC3);
for(int i = 0; i< contours.size(); i++)
{
Scalar color = Scalar(255,0,255);
drawContours(drawing, contours_poly, i, color, 1, 8, vector<Vec4i>(), 0, Point());
rectangle(drawing, boundRect[i].tl(), boundRect[i].br(), color, 2, 8, 0);
}
问候
你是如何绘制边界框的?你需要显示一些代码。 – 2013-02-08 19:46:12
@sftrabbit我添加了负责填充边界框的代码。希望这有助于 – Tomazi 2013-02-08 19:51:04