Ask Your Question
1

how to find the end point of a contour

asked 2016-09-07 05:44:50 -0600

shyam gravatar image

Hi All,

is there any function or way to find the end points of a contour ,i am able to find the contours in an image using the below code and in next step i need to get the start and end points for all of these contours

Imgproc.findContours(edges, contours, hierarchy, Imgproc.RETR_EXTERNAL, Imgproc.CHAIN_APPROX_SIMPLE);

Thanks

edit retag flag offensive close merge delete

Comments

1

They are not stored as rings. How about the first and last points in each returned contour? What was your first thought? The start and end of a contour are almost meaningless as they could be placed at any two adjacent points.

Der Luftmensch gravatar imageDer Luftmensch ( 2016-09-07 09:06:51 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2016-09-08 06:11:52 -0600

That is fairly simple. Each contour is in fact in the backend a vector<Point>. However, it is quite random in which way the start and end point are defined, based on the internal logic and the edges found during the process. If you don't mind that the position selected is kind of random, then you can find those points by

vector<Point> single_contour = contours[0];
Point begin = single_contour[0];
int lenght = single_contour.size();
Point end = single_contour[length-1];
edit flag offensive delete link more

Comments

1

Good answer.

livelock gravatar imagelivelock ( 2016-09-08 08:29:25 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-09-07 05:44:50 -0600

Seen: 2,387 times

Last updated: Sep 08 '16