The cvLine()
function can draw a straight line given two points P1(x1,y1) and P2(x2,y2). What I'm stuck at is getting the points on this line instead of drawing it straight away.
Suppose I draw a line (in green) AB and another line AC. If I follow all the pixels on line AB there will be a point where I encounter black pixels (the border of the circle that encloses A) before I reach B.
Again when traveling along the pixels on line AC black pixels will be encountered twice.
Basically I'm trying to get the points on the (green) lines, but cvLine()
doesn't seem to return any point sequence structure. Is there any way to get these points using OpenCV?
A rather dumb approach would be to draw the line using cvLine()
on a separate image, then find contours on it, then traverse that contour's CvSeq*
(the line drawn) for the points. Both the scratch image and the original image being of same size we'd be getting the points' positions. Like I said, kinda dumb. Any enlightened approach would be great!
I think a CvLinIterator does what you want.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With