1

I need to know how draw lines parallel, I'm beginning with Opencv, please help. I use the houghlines function for detect lines, now I want detect lines parallel, I know that the ecuacion of a lines is y = k*x+b and two lines are parallel when k1 = k2. but how represent this in opencv with houghlines?

1 Answer 1

3

The lines returned by HoughLines are in polar coordinates (ρ,θ):

http://docs.opencv.org/modules/imgproc/doc/feature_detection.html?highlight=houghlines#houghlines

lines – Output vector of lines. Each line is represented by a two-element vector (ρ, θ). ρ is the distance from the coordinate origin (0,0) (top-left corner of the image). θ is the line rotation angle in radians ( 0 ~ vertical line, π/2 ~ horizontal line ).

Lines with the same (within some error factor) angle θ are parallel.

HoughLinesP, on the other hand, returns the line endpoints, so you would have to calculate the slope of each line using:

m = (y2 - y1) / (x2 - x1)
Sign up to request clarification or add additional context in comments.

3 Comments

thanks for the reply, now that I have that slope, how I calculate the slope of the other line and then compare? something like this, but I don't know how to handle the vector lines[0]. here is the code dropbox.com/s/zngguzrp6svev0n/…
Have a look at this answer using itertools: stackoverflow.com/a/942551/1377097. You'll want combinations(). I suspect that part of your problem is that you're comparing every line to itself as well as the other lines, which will make every line parallel to something.
I don't understand your reply, however, I found this answer stackoverflow.com/a/14345425/4376296 and I have an idea of how to apply itertools.combination, however I don't know as fit this to the lines, any suggestions please? here is the code dropbox.com/s/eyl10cods3nvqpk/…

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.