#include
#include
#include
using namespace cv;
int main()
{
Mat src = imread("C:/Users/asus/Desktop/tupian/5.png");
if (src.empty())
{
printf("could not load image...\n");
return -1;
}
Mat dst, gray_image;
namedWindow("opencv setup demo", WINDOW_AUTOSIZE);
imshow("opencv setup demo", src);
cvtColor(src, gray_image, COLOR_BGR2GRAY);
imshow("gray_image", gray_image);
namedWindow("output window", WINDOW_AUTOSIZE);
adaptiveThreshold(~gray_image, dst, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 15, -2);
imshow("output window", dst);
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 temp;
erode(dst, temp, hline);
dilate(temp, dst, hline);
//morphologyEx(dst, dst, MORPH_OPEN, hline);
bitwise_not(dst, dst);
blur(dst, dst, Size(3, 3), Point(-1, -1));
imshow("1", dst);
waitKey(0);
return 0;
}
#include
#include
#include
using namespace cv;
int main()
{
Mat src = imread("C:/Users/asus/Desktop/tupian/6.png");
if (src.empty())
{
printf("could not load image...\n");
return -1;
}
Mat dst, gray_image;
namedWindow("opencv setup demo", WINDOW_AUTOSIZE);
imshow("opencv setup demo", src);
cvtColor(src, gray_image, COLOR_BGR2GRAY);
imshow("gray_image", gray_image);
namedWindow("output window", WINDOW_AUTOSIZE);
adaptiveThreshold(~gray_image, dst, 255, ADAPTIVE_THRESH_GAUSSIAN_C, THRESH_BINARY, 15, -2);
imshow("output window", dst);
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 kernel = getStructuringElement(MORPH_RECT, Size(3, 3), Point(-1, -1));
Mat temp;
erode(dst, temp, kernel);
dilate(temp, dst, kernel);
//morphologyEx(dst, dst, MORPH_OPEN, hline);
bitwise_not(dst, dst);
imshow("1", dst);
waitKey(0);
return 0;
}