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;
}
实现效果:

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