#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
//形态学操作
int Demo_Morphology()
{
char win1[] = "window1";
char win2[] = "window2";
Mat img1, img2;
img1 = imread("D://images//4//13.jpg");
if (img1.empty())
{
cout << "could not load img..."<< endl;
return 0;
}
imshow(win1,img1);
Mat kernel_close = getStructuringElement(MORPH_RECT,Size(35,35),Point(-1,-1));
Mat kernel_GRADIENT = getStructuringElement(MORPH_RECT, Size(15, 15), Point(-1, -1));
Mat kernel_top_hat = getStructuringElement(MORPH_RECT, Size(53, 53), Point(-1, -1));
Mat kernel_black_hat = getStructuringElement(MORPH_RECT, Size(11, 11), Point(-1, -1));
//
//morphologyEx(img1,img2,CV_MOP_CLOSE,kernel_close);
//梯度
//morphologyEx(img2, img2, CV_MOP_GRADIENT, kernel_GRADIENT);
//开操作-顶帽
//morphologyEx(img1, img2, CV_MOP_TOPHAT, kernel_top_hat);
//闭操作-黑帽
morphologyEx(img1, img2, CV_MOP_BLACKHAT, kernel_black_hat);
imshow(win2, img2);
return 0;
}
int main()
{
Demo_Morphology();
waitKey(0);
return 0;
}