轮廓提取过程中删除连通域面积小于某阈值的轮廓

#include#include #include #include #include usingnamespacestd;usingnamespacecv;intmain()

{

Mat srcImage;

Mat thresholdImage;

Mat grayImage;

srcImage = imread("1.png");

cvtColor(srcImage,grayImage,CV_BGR2GRAY);

threshold(grayImage, thresholdImage,0,255, CV_THRESH_OTSU+CV_THRESH_BINARY);

Mat resultImage;

thresholdImage.copyTo(resultImage);vector>contours;

findContours(resultImage,contours,CV_RETR_EXTERNAL,  CV_CHAIN_APPROX_NONE);vector>::iterator itc= contours.begin();while(itc!=contours.end())

{if( itc->size()<20)

{

itc= contours.erase(itc);

}else{

++itc;

}

}

drawContours(resultImage, contours, -1, Scalar(255), CV_FILLED);

imshow("原图",srcImage);

imshow("灰度",grayImage);

imshow("二值图",thresholdImage);

imshow("结果图",resultImage);

waitKey(0);return0;

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容