虚位以待(AD)
虚位以待(AD)
首页 > 软件编程 > C/C++编程 > c语言通过opencv实现轮廓处理与切割

c语言通过opencv实现轮廓处理与切割
类别:C/C++编程   作者:码皇   来源:互联网   点击:

这篇文章主要介绍了c语言通过opencv实现轮廓处理与切割,具有一定借鉴价值,需要的朋友可以参考下

注意在寻找轮廓时要选择中寻找外层轮廓

    RETR_EXTERNAL
    #include "opencv/cv.h" #include "opencv/highgui.h" using namespace std;
    using namespace cv;
    int main() {
    Mat srcimg=imread("./22.jpg");
    Mat dst;
    cvtColor(srcimg,dst,CV_BGR2GRAY);
    threshold(dst,dst,120,255,1);
    vector<vector<Point> > edgepoint;
    vector<Vec4i> lclass;
    findContours(dst,edgepoint,lclass,RETR_EXTERNAL,CHAIN_APPROX_NONE,Point());
    Mat mat[edgepoint.size()];
    for(int i=0;
    i<edgepoint.size();
    i++) {
    Rect rec=boundingRect(Mat(edgepoint[i]));
    mat[i]=dst(rec);
    rectangle(dst,rec,Scalar(100,80,90),1,1,0);
    drawContours(dst,edgepoint,i,Scalar(200),1,8,lclass);
    string str=to_string(i);
    imshow(str,mat[i]);
    }
    imshow("tt",dst);
    cout<<edgepoint.size()<<endl;
    waitKey(0);
    }

结果如下:

总结

以上就是本文关于c语言通过opencv实现轮廓处理与切割的全部内容,希望对大家有所帮助。感兴趣的朋友可以继续参阅本站其他相关专题,如有不足之处,欢迎留言指出。感谢朋友们对本站的支持!

您可能感兴趣的文章:

  • C语言实现opencv提取直线、轮廓及ROI实例详解
相关热词搜索: opencv 轮廓提取 opencv轮廓检测 opencv 轮