#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int elementSize = 3;
int maxSize = 260;
int Demo_Load_Img();
//图片膨胀
void Get_Img_Struct_Element_Dilate(int, void*);
//图片腐蚀
void Get_Img_Struct_Element_Erode(int, void*);
Mat img1, img2, structElement;
char win1[] = "window1";
char win2[] = "window2";
int Demo_Load_Img()
{
img1 = imread("D://images//4.jpg");
imshow(win1,img1);
//图片膨胀
//createTrackbar("Element Size:",win1,&elementSize,maxSize, Get_Img_Struct_Element_Dilate);
////图片膨胀
//Get_Img_Struct_Element_Dilate(0,0);
//图片腐蚀
createTrackbar("Element Size:", win1, &elementSize, maxSize, Get_Img_Struct_Element_Erode);
//图片腐蚀
Get_Img_Struct_Element_Erode(0, 0);
return 0;
}
//图片膨胀
void Get_Img_Struct_Element_Dilate(int,void*)
{
int size_1 = elementSize * 2 + 1;
structElement = getStructuringElement(MORPH_RECT,Size(size_1,size_1),Point(-1,-1));
//膨胀
dilate(img1,img2,structElement,Point(-1,-1),1);
imshow(win2,img2);
}
void Get_Img_Struct_Element_Erode(int,void*)
{
int size_1 = elementSize * 2 + 1;
structElement = getStructuringElement(MORPH_RECT, Size(size_1, size_1), Point(-1, -1));
//腐蚀
erode(img1, img2, structElement);
imshow(win2, img2);
}
int main()
{
Demo_Load_Img();
waitKey(0);
return 0;
}