膨胀是求最大值。即白色增多
腐蚀是求最小值,即黑色增多
#include<opencv2\opencv.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
//模糊原理
Mat src;
Mat dst_dilate, dst_erode;
int element_size = 3;
int max_size = 21;
char output_title[] = "output Image";
void CallBack_Demo(int, void*);
int main()
{src = imread("E:\\vs2015\\opencvstudy\\3.jpg", 1);if (src.empty()){cout << "could not load the src image!" << endl;return -1;}char *input_title = "input Image";imshow(input_title, src);namedWindow(output_title, 1);createTrackbar("Size:", output_title, &element_size, max_size, CallBack_Demo);CallBack_Demo(0, 0);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_dilate, structureElement, Point(-1, -1),1);//erode(src, dst_erode, structureElement, Point(-1, -1), 1);imshow(output_title, dst_dilate);/*imshow(output_title, dst_erode);*/return;}