Ask Your Question

pj's profile - activity

2014-04-07 03:06:57 -0600 commented question extract point sequence of edge (a not enclosed contour)

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.png http://i.imgur.com/oTFz0xj.png

2014-04-07 02:58:43 -0600 commented answer extract point sequence of edge (a not enclosed contour)

Thanks, but this doesnt seem to solve it, I have tested your suggestion and updated my Question. The edges in my actual Image are also of thickness=1

2014-04-07 02:55:18 -0600 received badge  Editor (source)
2014-04-06 12:06:37 -0600 asked a question 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:
input

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?