OpenCV 闭合轮廓检测(2)

// Iterate over each segment and draw it
 std::vector<cv::Point>::const_iterator itp= poly.begin();
 while (itp!=(poly.end()-1)) {
  cv::line(result,*itp,*(itp+1),cv::Scalar(0),2);
  ++itp;
 }
 // last point linked to first point
 cv::line(result,*(poly.begin()),*(poly.end()-1),cv::Scalar(20),2);

// testing the convex hull
 std::vector<cv::Point> hull;
 cv::convexHull(cv::Mat(contours[3]),hull);

// Iterate over each segment and draw it
 std::vector<cv::Point>::const_iterator it= hull.begin();
 while (it!=(hull.end()-1)) {
  cv::line(result,*it,*(it+1),cv::Scalar(0),2);
  ++it;
 }
 // last point linked to first point
 cv::line(result,*(hull.begin()),*(hull.end()-1),cv::Scalar(20),2);

// testing the moments

// iterate over all contours
 itc= contours.begin();
 while (itc!=contours.end()) {

// compute all moments
  cv::Moments mom= cv::moments(cv::Mat(*itc++));

// draw mass center
  cv::circle(result,
   // position of mass center converted to integer
   cv::Point(mom.m10/mom.m00,mom.m01/mom.m00),
   2,cv::Scalar(0),2); // draw black dot
 }

*/

cv::namedWindow("Some Shape descriptors");
 cv::imshow("Some Shape descriptors",result);


 cv::waitKey();
 return 0;


}

实现效果:

OpenCV 闭合轮廓检测

--------------------------------------分割线 --------------------------------------

Ubuntu Linux下安装OpenCV2.4.1所需包

Ubuntu 12.04 安装 OpenCV2.4.2

CentOS下OpenCV无法读取视频文件

Ubuntu 12.04下安装OpenCV 2.4.5总结

Ubuntu 10.04中安装OpenCv2.1九步曲

基于QT和OpenCV的人脸识别系统

[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9 

--------------------------------------分割线 --------------------------------------

OpenCV的详细介绍请点这里
OpenCV的下载地址请点这里

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/b8667c4faca4a923c91423c01ded9bc7.html