#include<opencv2\opencv.hpp>
#include<opencv2\highgui\highgui.hpp>
#include<iostream>
#include<math.h>
using namespace std;
using namespace cv;
int main11()
{
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 gray_image;
cvtColor(src, gray_image, CV_BGR2GRAY);
imshow("gray_image", gray_image);
Mat binImg;
adaptiveThreshold(gray_image, binImg, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, -2);
imshow("binImg", binImg);
Mat erodeImg;
Mat dilateImg;
//提取水平结构元素
Mat hline = getStructuringElement(MORPH_RECT, Size(src.cols / 16, 1), Point(-1, -1));
//提取垂直结构元素
Mat vline = getStructuringElement(MORPH_RECT, Size(1, src.rows / 16), Point(-1, -1));
//矩形结构元素
Mat kernal = getStructuringElement(MORPH_RECT, Size(5, 5), Point(-1, -1));
/*erode(binImg, erodeImg, vline);
dilate(erodeImg, dilateImg, vline);*/
//等价于开操作
morphologyEx(binImg, dilateImg, CV_MOP_OPEN, vline);
imshow("Result", dilateImg);
waitKey(0);
return 0;
}