Mat element1 = getStructuringElement(MORPH_RECT, Size(70, 1));// size的width应大于图像中的横向笔划
Mat element3 = getStructuringElement(MORPH_RECT, Size(1, 55));//size的height应大于图像中的竖直笔划
morphologyEx(image, imageF1, MORPH_CLOSE, element1);
morphologyEx(image, imageF4, MORPH_CLOSE, element3);
#include "core/core.hpp" #include "highgui/highgui.hpp" #include "imgproc/imgproc.hpp" #include <iostream> using namespace std;using namespace cv; int main(){ Mat image = imread("E://x.jpg", 1); Mat imageF1, imageF2, imageF3, imageF4, imageF5, imageF6, imageF7; cvtColor(image, image, CV_RGB2GRAY); namedWindow("原图"); imshow("原图", image); Mat element1 = getStructuringElement(MORPH_RECT, Size(73, 1)); Mat element3 = getStructuringElement(MORPH_RECT, Size(1, 80)); morphologyEx(image, imageF1, MORPH_CLOSE, element1); threshold(imageF1, imageF2, 200, 255, CV_THRESH_OTSU | CV_THRESH_BINARY_INV);//自适应阈值 morphologyEx(image, imageF4, MORPH_CLOSE, element3); threshold(imageF4, imageF5, 200, 255, CV_THRESH_OTSU | CV_THRESH_BINARY_INV); bitwise_or(imageF2, imageF5, imageF7); namedWindow("F1"); imshow("F1", imageF1); namedWindow("F2"); imshow("F2", imageF2); namedWindow("F4"); imshow("F4", imageF4); namedWindow("F7"); imshow("F7", imageF7); namedWindow("F5"); imshow("F5", imageF5); waitKey(0); return 0;}