# extract point sequence of edge (a not enclosed contour)

Hello,

i am trying to extract the point sequence of a single (curvy) edge, which i obtained with the CannyEdge-Filter. When I use findContours(...EXTERNAL...) i receive a enclosed contour, say for example p1->p2->p3->p4->p3->p2->p1 - but what i really want is just a "one-way-sequence" like p1->p2->p3->p4. I currently use an ugly workaround, where I detect the fraction of the extracted contours which has no reduntant points in it, but this is kind of ineffective and i wonder if there is an easier way to get what I need.

@Haris: i have tried your suggestion and got the following output:

input image:

contour 0:
x: 5, y: 20
x: 14, y: 20
x: 15, y: 21
x: 32, y: 21
x: 33, y: 22
x: 50, y: 22
x: 51, y: 23
x: 68, y: 23
x: 69, y: 24
x: 86, y: 24
x: 87, y: 25
x: 95, y: 25
x: 87, y: 25
x: 86, y: 24
x: 69, y: 24
x: 68, y: 23
x: 51, y: 23
x: 50, y: 22
x: 33, y: 22
x: 32, y: 21
x: 15, y: 21
x: 14, y: 20

using this code:

    Mat input(50,100,CV_8UC1);
input.setTo(0);
line(input, Point(5,20), Point(95,25), Scalar(255), 1);

namedWindow( "input", CV_WINDOW_AUTOSIZE );
imshow( "input", input );

vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
findContours( input, contours, hierarchy, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

for (vector<vector<Point>>::iterator outter = contours.begin(); outter < contours.end(); outter++)
{
printf("contour %d:\n", outter - contours.begin());
for (vector<Point>::iterator inner = (*outter).begin(); inner < (*outter).end(); inner++)
{
Point cur = (*inner);
printf("x: %d, y: %d\n", cur.x, cur.y);
}
}


See what I mean?

edit retag close merge delete

Can you post original image?

( 2014-04-07 02:57:11 -0500 )edit

by original images you mean the ones that i actually have the problem with? the (canny-edge) images look like this: http://i.imgur.com/5noxbbU.pnghttp://i.imgur.com/oTFz0xj.png

( 2014-04-07 03:06:57 -0500 )edit

You can refer the answer here might be helpful

( 2014-04-07 04:34:51 -0500 )edit

Sort by ยป oldest newest most voted

Hey Having the Same Problem . Please Help. How do i Connect all the points to form a continuous sequence.

more

Official site

GitHub

Wiki

Documentation

## Stats

Asked: 2014-04-06 12:06:37 -0500

Seen: 1,134 times

Last updated: Apr 07 '14