Alex Rivera | Logout

How to get points from a line in OpenCV?

Asked 2011-07-14T06:31:01.427
11

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.

line points

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!

Edit
Report

1 Answer

13

I think a CvLinIterator does what you want.

answered 2011-07-14T08:31:24.830

Your Answer