——检测毛刺
作者:互联网
检测以下图像中的毛刺:
代码:
cv::Mat Image = cv::imread("fin3.png", CV_LOAD_IMAGE_GRAYSCALE);
imshow("src", Image);
cv::Mat color;
cvtColor(Image, color, ColorConversionCodes::COLOR_GRAY2BGR);
//分割出环形区域
cv::Mat Region,close_region;
threshold(Image, Region, 100, 255, THRESH_BINARY);
imshow("Region", Region);
int elementsize = 39;
//设定圆形算子 3*3大小的核
cv::Mat element2 = getStructuringElement(cv::MorphShapes::MORPH_ELLIPSE, cv::Size(elementsize, elementsize));
morphologyEx(Region, close_region, CV_MOP_CLOSE, element2, cv::Point(-1, -1), 7, cv::BORDER_CONSTANT, cv::morphologyDefaultBorderValue());
imshow("close_region", close_region);
cv::Mat diff = close_region - Region;
imshow("diff", diff);
elementsize = 3;
element2 = getStructuringElement(cv::MorphShapes::MORPH_ELLIPSE, cv::Size(elementsize, elementsize));
morphologyEx(diff, diff, CV_MOP_OPEN, element2, cv::Point(-1, -1), 1, cv::BORDER_CONSTANT, cv::morphologyDefaultBorderValue());
imshow("result", diff);
color.setTo(cv::Scalar(0,0,255), diff);
imshow("毛刺", color);
waitKey(0);
效果:
标签:elementsize,毛刺,Region,imshow,检测,close,diff,cv 来源: https://blog.csdn.net/thequitesunshine007/article/details/123605852