获取包围对象的多边形 approxPolyDP

来源:互联网 发布:淘宝怎么看卖家销量 编辑:程序博客网 时间:2024/06/10 11:02
// testing the approximate polygon
std::vector<cv::Point> poly;
cv::approxPolyDP(cv::Mat(contours[2]),poly,
5, // accuracy of the approximation
true); // yes it is a closed shape
  1. // 轮廓表示为一个多边形 
  2. vector<Point> poly; 
  3. approxPolyDP(Mat(contours[2]), poly, 5, true); 
  4. vector<Point>::const_iterator itp = poly.begin(); 
  5. while (itp != (poly.end() - 1)) 
  6.     line(result, *itp, *(itp + 1), Scalar(255), 2); 
  7.     ++itp; 
  8. line(result, *itp, *(poly.begin()), Scalar(255), 2);