//查找轮廓 int cmin = 10; // 轮廓最短值 int cmax = 1000; // 轮廓最长值 findContours( canny_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) ); std::vector<std::vector<cv::Point>>::const_iterator itc = contours.begin(); while (itc != contours.end()) //清楚图像的噪声点 { // 移除过长或过短的轮廓 if (itc->size() < cmin || itc->size() > cmax) itc = contours.erase(itc); else ++itc; }