std::vector<cv::Point> resultpoly; cv::approxPolyDP(contours[0], resultpoly,4, true);//轮廓contours[0] ,resultpoly多边形的点集 cv::polylines(src, resultpoly, true, 150, 1);//画多边形的外轮廓 cv::imshow("detected polyLines", src);//显示多边形的外轮廓 //相关链接https://www.cnblogs.com/donaldlee2008/p/5230032.html // 移除过小或过大的轮廓 void getSizeContours(vector<vector<Point>> &contours) { int cmin = 100; // 最小轮廓长度 int cmax = 1000; // 最大轮廓长度 vector<vector<Point>>::iterator itc = contours.begin(); while(itc != contours.end()) { if((itc->size()) < cmin || (itc->size()) > cmax) { itc = contours.erase(itc); } else ++ itc; } }