Ask Your Question

Revision history [back]

Hough lines: minimum line length parameter not working?

I am trying to detect right-angle corners with Hough Line. Unfortunately, I can't work out how to get the minimum line length setting to do anything.

Here is my original image:

image description

Here are the canny edges:

image description

And here are the detected Hough lines. No matter what I change the min line length parameter to, all the lines still appear.

image description

This is my code:

gray = cv2.cvtColor(corner_img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 200)
cv2.imwrite('cropped_sw_corner-canny.png', edges)
minLineLength = 10 # Changing this to 100 does nothing.
maxLineGap = 1
threshold = 100
lines = cv2.HoughLinesP(edges,1,np.pi/180,threshold,minLineLength,maxLineGap)
for l in lines:
    for x1,y1,x2,y2 in l:
        cv2.line(corner_img,(x1,y1),(x2,y2),(0,0,255), 2)
cv2.imwrite('houghlines.jpg', corner_img)

I'm using OpenCV 3.4.0.14 on OSX with Python 2.7.

Hough lines: minimum line length parameter not working?

I am trying to detect right-angle corners with Hough Line. Unfortunately, I can't work out how to get the minimum line length setting to do anything.

Here is my original image:

image description

Here are the canny edges:

image description

And here are the detected Hough lines. No matter what I change the min line length parameter to, all the lines still appear. appear, including the tiny ones.

image description

This is my code:

gray = cv2.cvtColor(corner_img, cv2.COLOR_BGR2GRAY)
edges = cv2.Canny(gray, 100, 200)
cv2.imwrite('cropped_sw_corner-canny.png', edges)
minLineLength = 10 # Changing this to 100 does nothing.
maxLineGap = 1
threshold = 100
lines = cv2.HoughLinesP(edges,1,np.pi/180,threshold,minLineLength,maxLineGap)
for l in lines:
    for x1,y1,x2,y2 in l:
        cv2.line(corner_img,(x1,y1),(x2,y2),(0,0,255), 2)
cv2.imwrite('houghlines.jpg', corner_img)

I'm using OpenCV 3.4.0.14 on OSX with Python 2.7.