opencv2,找轮廓,用周长筛选

    xiaoxiao2021-03-25  12

    //---------找轮廓-------- Mat f_c=dst_d2.clone(); imshow("f_cc",f_c); vector<vector<Point>>contours; vector<Vec4i>hierarchy; findContours(f_c,contours,hierarchy,CV_RETR_TREE,CV_CHAIN_APPROX_NONE);//复杂:输入图像、轮廓数组、分层表示、以树状结构获取轮廓,获取每个轮廓的每个像素 //findContours(f_c,contours,CV_RETR_EXTERNAL,CV_CHAIN_APPROX_NONE);//简单:输入图像、轮廓数组、获取外轮廓、获取每个轮廓的每个像素 //白色图像上绘制黑色轮廓 Mat w_map(f_c.size(),CV_8U,Scalar(255)); int cmin=50,cmax=500;//周长的上下限 std::vector<std::vector<Point>>::const_iterator itc=contours.begin(); while (itc!=contours.end()) { if (itc->size()<cmin||itc->size()>cmax) { itc=contours.erase(itc); else { ++itc; } } drawContours(w_map,contours,-1,Scalar(0),1);//-1:绘制所有轮廓,1:轮廓线宽度
    转载请注明原文地址: https://ju.6miu.com/read-300299.html

    最新回复(0)