opencv 图像腐蚀膨胀 erode dilate

#include "iostream"
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;

int main()
{
	Mat  img, dst, dstbin, distancetransform,rel, rel2;

	img = imread("m3.jpg");
	//转为灰度图
	cvtColor(img, dst, COLOR_BGR2GRAY);
	//二值化,找出目标区域
	threshold(dst, dstbin, 150, 255, THRESH_BINARY);
	//创建用于腐蚀的结构元素
	Mat kernel = getStructuringElement(1, Size(3, 3));
	//腐蚀图像
	erode(dstbin, rel, kernel);
	//膨胀图像
	dilate(rel, rel2, kernel);

	imshow("原图", dstbin);
	imshow("腐蚀", rel);
	imshow("膨胀", rel2);

	waitKey(0);

	return 1;
}

opencv 图像腐蚀膨胀 erode dilate_第1张图片

你可能感兴趣的:(Opencv,opencv,人工智能,计算机视觉)