gpt4 book ai didi

c++ - 从图像中删除不需要的线条

转载 作者:太空狗 更新时间:2023-10-29 22:58:26 25 4
gpt4 key购买 nike

我目前正在从事一个读取图像、应用多个过滤器的项目,目的是能够在感兴趣的区域周围放置一个边界矩形。

我有一张横格纸上的手写文本图像作为我的输入:

string imageLocation = "loctation of image file";
src = imread(imageLocation, 1);

Inputted image

然后我将图像转换为灰度并应用自适应阈值:

cvtColor(src, newsrc, CV_BGR2GRAY);
adaptiveThreshold(~newsrc, dst, 255, CV_ADAPTIVE_THRESH_MEAN_C, THRESH_BINARY, 15, -2);

Applied adaptive thresholding

然后我使用形态学操作来尝试从图像中消除水平线:

Mat horizontal = dst.clone();

int horizontalSize = dst.cols / 30;
Mat horizontalStructure = getStructuringElement(MORPH_RECT, Size(horizontalSize,1));

erode(horizontal, horizontal, horizontalStructure, Point(-1, -1));
dilate(horizontal, horizontal, horizontalStructure, Point(-1, -1));

cv::resize(horizontal, horizontal, cv::Size(), 0.5, 0.5, CV_INTER_CUBIC);
imshow("horizontal", horizontal);

产生以下内容(到目前为止还不错): Input image horizontal line seperation

然后我尝试使用相同的腐 eclipse 和扩张方法来计算垂直方向:

int verticalsize = dst.rows / 30;
Mat verticalStructure = getStructuringElement(MORPH_RECT, Size( 1,verticalsize));

erode(vertical, vertical, verticalStructure, Point(-1, -1));
dilate(vertical, vertical, verticalStructure, Point(-1, -1));

cv::resize(vertical, vertical, cv::Size(), 0.5, 0.5, CV_INTER_CUBIC);
imshow("vertical", vertical);

我正在关注 OpenCV 的示例,可以在 here 中找到它

但是,我得到的垂直输出是: Vertical output

我的问题是,我将如何从图像中移除这些水平线。

很抱歉这个冗长的问题(我想尽可能多地解释)并提前感谢您的任何建议。

最佳答案

您可以像这里一样尝试在频域中进行这项工作:

http://lifeandprejudice.blogspot.ru/2012/07/activity-6-enhancement-in-frequency_25.html

http://www.fmwconcepts.com/imagemagick/fourier_transforms/fourier.html

使用 FFT 可以非常有效地从图像中添加/删除规则网格。

关于c++ - 从图像中删除不需要的线条,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40704469/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com