0

输入图像 我正在尝试使用 OpenCV 从扫描图像中删除背景网格线,直到现在我已经使用 HoughLine 方法来检测线条并用白色填充它。通过这种方法,我能够检测到水平线,但不能检测到垂直线。这是我的代码

'''

import cv2
import numpy as np

def rmv_lines(Image_Path):
    img = cv2.imread(Image_Path)
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
    edges = cv2.Canny(gray,50,150,apertureSize = 3)
    minLineLength, maxLineGap = 100, 15
    lines = cv2.HoughLinesP(edges,1,np.pi/180,100,minLineLength,maxLineGap)
    for x in range(0, len(lines)):
        for x1,y1,x2,y2 in lines[x]:
        #if x1 != x2 and y1 != y2:
            cv2.line(img,(x1,y1),(x2,y2),(255,255,255),4)
    return cv2.imwrite('removed.jpg',img)

'''

任何帮助或建议...

4

0 回答 0