#include <iostream>
#include <opencv2\opencv.hpp>
#include <math.h>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("E:\\3.jpg",IMREAD_UNCHANGED), dst;
if (!src.data) {
cout << "failed!" << endl;
return 0;
}
namedWindow("input_image", WINDOW_AUTOSIZE);
namedWindow("output_image", WINDOW_AUTOSIZE);
imshow("input_image", src);
dst = Mat::zeros(src.size(), src.type());
Mat gray;
/*转化为灰度图像*/
cvtColor(src, gray, COLOR_BGR2GRAY);
/*转化为二值图像*/
adaptiveThreshold(gray, dst, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 15, -2);
/*提取的目标*/
int xsize = dst.cols / 30;
int ysize = dst.rows / 30;
/*水平线*/
Mat hor = getStructuringElement(MORPH_RECT, Size(xsize, 1), Point(-1, -1));
/*垂直线*/
Mat vec = getStructuringElement(MORPH_RECT, Size(1, ysize), Point(-1, -1));
Mat hbin;
hbin = Mat::zeros(dst.size(), dst.type());
morphologyEx(dst, hbin, MORPH_OPEN, vec);
imshow("output_image", hbin);
waitKey(0);
return 0;
}