2

I'm working on a edge-detection/line-drawing vision project (using OpenCV and Python).
I'm able to find the edges I want in an image, using cv2.Canny(), and draw lines on those edges, using HoughLinesP().
I'm trying to figure out how to find the "end points" of the lines drawn using HoughLinesP() so that I can compare slopes of the lines to a value range (basically, I'm trying to see if those lines are vertical-enough to be "good").
I'm a little stuck on the finding the points of the lines drawn using HoughLinesP() though.
My code that's drawing the lines is

lines = cv2.HoughLinesP(img, RHO, THETA, minLineLength, maxLineGap)  
a, b, c = lines.shape  
for i in range(a):  
     cv2.line(img, (lines[i][0][0], lines[i][0][1], lines[i][0][2], lines[i][0][3], (0,255,0), 3, cv2.LINE_AA)

now, I can find the "shape" of the array, lines, but I'm not sure what the values mean... basically, where do I go from here?

>>x = lines.shape
>>print(x)

returns (1038, 1, 4) .

I understand that it's a 3D array. But how do I determine which points in the image correspond to which elements in the array?
Is there a way to correlate an element in 'line' to a pixel on the image?

Thank you!

EDIT:

print([lines[0]])
returns:
[array([[348, 159, 348, 159]])]

Which I think corresponds to (x_start, y_start),(x_end,y_end) points of a single line (the particular point above seems to be for a single point, ie the same start and end coordinates). If I'm understanding everything properly.

But, when trying to find the maximum x and y coordinates (the "top" and "bottom" of the line), I'm getting weird results.

This is what I'm doing:

a,b,c = lines.shape for i in range(a): max_y = np.maximum(lines[i][0][1], lines[i][0][3]) min_y = np.minimum(lines[i][0][1], lines[i][0][3])

Now, when I go back and print and show the results of the those statements... I don't get the points on the lines... what gives?

2
  • Did you figure out where the problem was here?
    – Jeru Luke
    Apr 27, 2017 at 17:58
  • not totally ... but I think: lines: a vector that stores the parameters (x_start, y_start, x_end, y_end) of the detected lines, ie, a point will look like [348, 159, 348, 159]
    – slow_one
    Apr 27, 2017 at 18:06

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.