opencv10-形态学操作

 主要针对二值图像和灰度图

#include<opencv2\opencv.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
int main()
{
	Mat src = imread("E:\\vs2015\\opencvstudy\\1.jpg", 1);
	if (src.empty())
	{
		cout << "could not load the src image!" << endl;
		return -1;
	}
	char *input_title = "input Image";
	imshow(input_title, src);

	Mat dst_open,dst_close,dst_gradient,dst_tophat,dst_blackhat;
	char output_title[] = "output Image";
	Mat kernal = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
	morphologyEx(src, dst_open, CV_MOP_OPEN, kernal);
	imshow("dst_open", dst_open);

	morphologyEx(src, dst_close, CV_MOP_CLOSE, kernal);
	imshow("dst_close", dst_close);

	morphologyEx(src, dst_gradient, CV_MOP_GRADIENT, kernal);
	imshow("dst_gradient", dst_gradient);

	morphologyEx(src, dst_tophat, CV_MOP_TOPHAT, kernal);
	imshow("dst_tophat", dst_tophat);

	morphologyEx(src, dst_blackhat, CV_MOP_BLACKHAT, kernal);
	imshow("dst_blackhat", dst_blackhat);

	waitKey(0);
	return 0;
}

猜你喜欢

转载自blog.csdn.net/weixin_38383877/article/details/89213515