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
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)
3 Comments
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.