首页 > 代码库 > opencv 形态学操作应用-提取水平与垂直线
opencv 形态学操作应用-提取水平与垂直线
adaptiveThreshold(~gray_src, binImg, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, -2);
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; int main(int argc, char** argv) { Mat src, dst; src = imread("E:/opencv3.2/TestOpenCVInstall/Debug/chars.png"); if (!src.data) { printf("could not load image...\n"); return -1; } char INPUT_WIN[] = "input image"; char OUTPUT_WIN[] = "result image"; namedWindow(INPUT_WIN, CV_WINDOW_AUTOSIZE); imshow(INPUT_WIN, src); Mat gray_src; cvtColor(src, gray_src, CV_BGR2GRAY); imshow("gray image", gray_src); Mat binImg; adaptiveThreshold(~gray_src, binImg, 255, ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, -2); imshow("binary image", binImg); // 水平结构元素 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(binImg, temp, kernel); dilate(temp, dst, kernel); // morphologyEx(binImg, dst, CV_MOP_OPEN, vline); bitwise_not(dst, dst); //blur(dst, dst, Size(3, 3), Point(-1, -1)); imshow("Final Result", dst); waitKey(0); return 0; }
opencv 形态学操作应用-提取水平与垂直线
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。