opencv 形态学操作应用-提取水平与垂直线
Posted 蒙蒙大川
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 形态学操作应用-提取水平与垂直线的主要内容,如果未能解决你的问题,请参考以下文章
youcans 的 OpenCV 例程200篇130. 形态学之提取水平和垂直线