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?
Asked
Active
Viewed 2,281 times
1 Answers
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)

beaker
- 16,331
- 3
- 32
- 49
-
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 https://www.dropbox.com/s/zngguzrp6svev0n/Captura%20de%20pantalla%20de%202015-01-14%2011%3A25%3A11.png?dl=0 – Gui Jan 14 '15 at 15:58
-
Have a look at this answer using `itertools`: http://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. – beaker Jan 14 '15 at 17:12
-
I don't understand your reply, however, I found this answer http://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 https://www.dropbox.com/s/eyl10cods3nvqpk/Captura%20de%20pantalla%20de%202015-01-14%2015%3A05%3A42.png?dl=0 – Gui Jan 14 '15 at 19:42