设为首页 加入收藏

TOP

OpenCV 闭合轮廓检测(二)
2015-02-02 14:36:41 来源: 作者: 【 】 浏览:22
Tags:OpenCV 闭合 轮廓 检测
rect,cv::Scalar(0),2);


?// testing the approximate polygon
?std::vector poly;
?cv::approxPolyDP(cv::Mat(contours[2]),poly,5,true);


?std::cout << "Polygon size: " << poly.size() << std::endl;


?// Iterate over each segment and draw it
?std::vector::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 hull;
?cv::convexHull(cv::Mat(contours[3]),hull);


?// Iterate over each segment and draw it
?std::vector::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;



}


实现效果:



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


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


首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
分享到: 
上一篇【OpenCV】透视变换 Perspective .. 下一篇OpenCV 轮廓检测心得笔记

评论

帐  号: 密码: (新用户注册)
验 证 码:
表  情:
内  容: