Ask Your Question
0

extract point sequence of edge (a not enclosed contour)

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

pj gravatar image

updated 2014-04-07 02:55:18 -0500

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?

edit retag flag offensive close merge delete

Comments

Can you post original image?

Haris gravatar imageHaris ( 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

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

You can refer the answer here might be helpful

Haris gravatar imageHaris ( 2014-04-07 04:34:51 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2015-06-30 07:45:01 -0500

jitesh gravatar image

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

edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

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

Seen: 1,134 times

Last updated: Apr 07 '14