// 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;
}
实现效果:
--------------------------------------分割线 --------------------------------------
CentOS下OpenCV无法读取视频文件
[翻译]Ubuntu 14.04, 13.10 下安装 OpenCV 2.4.9
--------------------------------------分割线 --------------------------------------