c++ - 计算边界框的面积

标签 c++ opencv

你好 StackOverflowers

我创建了一个应用程序,它使用 inRange 函数根据预定义的颜色分割图像。然后我在检测到的对象周围绘制边界框。

我的问题是如何确定区域属性,例如:面积、大小、高度和中心点。

我在这里放置了一个屏幕转储示例.....

enter image description here

我应该如何检索这些边界框或任何其他被淹没的边界框的区域属性......?

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

问候

最佳答案

您可以使用内置的 OpenCV 获取面积 function .那里还有其他功能来获得您需要的一切。

关于c++ - 计算边界框的面积,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14780138/

相关文章:

python - 当在 csv 中提取坐标和帧数时,如何在视频上绘制边界框?

matlab - 训练新的 LatentSVMDetector 模型

c++ - 如何将操纵器匹配为模板参数并为特定的操纵器启用函数调用

ios - 构建框架 IOS OpenCV 3.1.0.2 在 MAC (OS X El Capitan) 上失败

c++ - 如何有效地将 vector<pair<int,int>> 转换为 multimap<int,int>?

c++ - 结构比较器访问 C++ 中的另一个字段

python - 使用opencv检测没有眉毛和下巴的人脸

python-3.x - opencv 中的 ROI 坐标如何工作

c++ - 什么是 undefined reference /未解析的外部符号错误,我该如何解决?

C++ 这是一个不完整的类型吗?