Python cv2 HoughLines grid line detection

杀马特。学长 韩版系。学妹 提交于 2019-12-03 16:36:11

I ended up iterating through the lines and removing lines that were within 10px of one another:

lines = cv2.HoughLinesP(edges,1,np.pi/180,275, minLineLength = 600, maxLineGap = 100)[0].tolist()

for x1,y1,x2,y2 in lines:
    for index, (x3,y3,x4,y4) in enumerate(lines):

        if y1==y2 and y3==y4: # Horizontal Lines
            diff = abs(y1-y3)
        elif x1==x2 and x3==x4: # Vertical Lines
            diff = abs(x1-x3)
        else:
            diff = 0

        if diff < 10 and diff is not 0:
            del lines[index]

gridsize = (len(lines) - 2) / 2

you can dilate the image with kernel = cv2.getStructuringElement(cv2.MORPH_CROSS, (2, 2)) dilated = cv2.dilate(edges, kernel, iterations=5) then apply cv2.HoughLinesP

Doesn't the Hough function have a parameter that does exactly this? MaxLineGap? So if your lines were 2px thick, you set that parameter to 3? Does it not work?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!