相关疑难解决方法(0)

从文本图像中删除非直线

我有一个包含文本但有非直线绘制的图像。

在此处输入图片说明

我想删除这些行而不影响/删除文本中的任何内容。
为此,我使用了霍夫概率变换:

import cv2
import numpy as np


def remove_lines(filename):
    img = cv2.imread(filename)
    gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray, 50, 200)
    lines = cv2.HoughLinesP(edges, rho=1, theta=1*np.pi/180,
                            threshold=100, minLineLength=100, maxLineGap=5)
    # Draw lines on the image
    for line in lines:
        x1, y1, x2, y2 = line[0]
        cv2.line(img, (x1, y1), (x2, y2), (0, 0, 255), 3)

    cv2.imwrite('result', img) 
Run Code Online (Sandbox Code Playgroud)

结果不如我预期的好:

在此处输入图片说明

没有完全检测到线条(仅检测到线条的某些线段,直线段)。
我对cv2.Cannycv2.HoughLinesP参数做了一些调整,但是也没有用。

我也尝试过cv2.createLineSegmentDetector(由于许可证问题,在最新版本的opencv中不可用,因此我不得不将opencv降级到4.0.0.21版):

import cv2
import numpy as np
def remove_lines(filename):
    im = cv2.imread(filename)
    gray …
Run Code Online (Sandbox Code Playgroud)

python opencv image image-processing line

5
推荐指数
1
解决办法
107
查看次数

标签 统计

image ×1

image-processing ×1

line ×1

opencv ×1

python ×1