I'm using OpenCV to fit a line from a set of points using cvFitLine()
cvFitLine()
returns a normalized vector that is co-linear to the line and a point on the line.
See details here
Using this information how can I get the equation of a line so that I can draw the line?
-
If
cvFitLine()
returns normalized vector(vx,vy)
and point(x0,y0)
, then the equation of the line is(x,y) = (x0,y0) + t*(vx,vy)
where
t
runs from −∞ to +∞.This is what you asked for, but probably isn't immediately helpful in drawing the line. You would want to clip it either to the screen boundaries, or perhaps the bounding box of the the original set of points. To clip a line to a rectangle, just solve for values of
t
where the line crosses the boundary of the rectangle. -
Just draw a big line instead of solving for the boundaries. eg:
cv.Line(img, (x0-m*vx[0], y0-m*vy[0]), (x0+m*vx[0], y0+m*vy[0]), (0,0,0))
will do it for example.. for m large enough :)
0 comments:
Post a Comment