Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get points from a line in OpenCV?

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!

like image 331
AruniRC Avatar asked Jul 14 '11 06:07

AruniRC


1 Answers

I think a CvLinIterator does what you want.

like image 73
jilles de wit Avatar answered Nov 09 '22 08:11

jilles de wit