简体   繁体   English

如何使用cv2和python删除图像中的虚线

[英]How to remove the dash lines in the images using cv2 and python

I am new to do image precessing. 我是新来做图像处理的。 I am trying to remove the dash lines and dotted lines from the images using cv2 in python, but have some difficulties. 我正在尝试在python中使用cv2从图像中删除虚线和虚线,但是有一些困难。

What I have tried: 我尝试过的

(1) I got some idea from How to remove horizontal and vertical lines from an image , to remove the lines in the image. (1)我从如何删除图像中的水平线和垂直线 ,删除图像中的线中获得了一些想法。 So I want to plot the dash lines into lines, and then, remove them. 因此,我想将虚线绘制成线,然后将其删除。 I used the Hough Tranform ( Python How to detect vertical and horizontal lines in an image with HoughLines with OpenCV? ) and ( opencv detect dotted lines ), but it introduces a lot of unnecessary lines that mess up all the numbers and words. 我使用了Hough变换( Python如何使用OpenCV的HoughLines检测图像中的垂直线和水平线? )和( opencv检测虚线 ),但是它引入了很多不必要的行,使所有数字和单词弄乱了。 I tuned the 'minLineLength' and 'maxLineGap' but do not help. 我调整了“ minLineLength”和“ maxLineGap”,但没有帮助。 The reason for these is there are some points in the words and numbers have the same 'maxLineGap' as the dash lines, so there are all plotted into lines. 原因是单词中的一些点和数字与虚线具有相同的“ maxLineGap”,因此它们全部绘制成线。 So if I remove the lines, I would remove the part of characters and numbers that have lines, such as 'Liabilities' and '28,056,622'. 因此,如果删除行,则会删除包含行的字符和数字部分,例如“负债”和“ 28,056,622”。

(2) I tried to use: (2)我尝试使用:

horizontalStructure = cv2.getStructuringElement(cv2.MORPH_RECT, (horizontalsize,1))

But I am not sure how to represent dash lines pattern, and CV_SHAPE_CUSTOM is not available in the cv2. 但是我不确定如何表示虚线模式,并且cv2中不提供CV_SHAPE_CUSTOM。

Please provide me with some suggestions. 请给我一些建议。 Thanks! 谢谢!

The original file 原始文件 在此处输入图片说明

The image after I plot line accross the dash lines 我在虚线上画线后的图像

在此处输入图片说明

This is quite old post however if in case useful to someone. 这是相当老的帖子,但是如果对某人有用的话。 Use cv2.dilate to get dotted line into a straight line followed by cv2.getStructuringElement to remove the lines. 使用cv2.dilate将虚线变为一条直线,然后使用cv2.getStructuringElement删除这些线。 Experiment with the dilate iterations in cv2.dilate and horizontal line size within cv2.getStructuringElement for better results. cv2.dilate进行扩张迭代,并在cv2.dilate水平线尺寸, cv2.getStructuringElement获得更好的结果。 If dilation affects the characters/digits, create a mask using cv2.bitwise methods (and, or, xor) and apply only the mask over lines. 如果膨胀会影响字符/数字,请使用cv2.bitwise方法(和,或,或,异或)创建遮罩,并仅cv2.bitwise应用遮罩。 hth! hth!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM