#include<opencv2\opencv.hpp>
#include<highgui.h>
#include<iostream>
using namespace std;
using namespace cv;
Mat src, dst;
int element_size = 3;
int max_size = 21;
void CallBack_Demo(int element_size, void*);
int main(int argc, char** argv)
{
// read image
src = imread("C:/Users/qxq/Pictures/image/1.jpg");
if (src.empty())
{
printf("Could not load image...");
return -1;
}
namedWindow("output", CV_WINDOW_AUTOSIZE);
//界面处理,出现阈值滚动条
createTrackbar("Element Size:", "output", &element_size, max_size, CallBack_Demo);
CallBack_Demo(0,0);
imshow("input", src);
waitKey(0);
return 0;
}
void CallBack_Demo(int , void*)
{
int s = element_size * 2 + 1;
Mat structureElement = getStructuringElement(MORPH_RECT,Size(s,s),Point(-1,-1));
//膨胀操作
dilate(src, dst, structureElement, Point(-1, -1));
//腐蚀操作
//erode(src, dst, structureElement, Point(-1, -1));
imshow("output", dst);
}