views:

1566

answers:

3

Hi,

reference, OpenCv\samples\c\lkdemo.c

Anybody know what does the following snippet of codes does ?

Code extracted from lkdemo.c

 for( i = k = 0; i < count; i++ )
            {
                if( add_remove_pt )
                {
                    double dx = pt.x - points[1][i].x;
                    double dy = pt.y - points[1][i].y;

                    if( dx*dx + dy*dy <= 25 )
                    {
                        add_remove_pt = 0;
                        continue;
                    }
                }

                if( !status[i] )
                    continue;

                points[1][k++] = points[1][i];
                cvCircle( image, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
            }
            count = k;

Q1.

What does the bold line does ? >> points[1][k++] = points[1][i];

Why k++ ? I am confuse, thinking that next point is overwritten by the current point

Q2.

As cvCircle id drawn as the frame loops, where is the old points cleared and new point drawn ?

I look forward to your inputs.

Thanks =)

+2  A: 

Q1:

Perhaps it would help if I refactor the code:

if( status[i] ) {
    points[1][k++] = points[1][i];  // <---- Q1
    cvCircle( image, cvPointFrom32f(points[1][i]), 3, CV_RGB(0,255,0), -1, 8,0);
}

So in the line for question 1, i always increments (it's incremented by the loop) but k only increments when status[i] is true. In short, it eliminates any points in the array where status[i] is false by copying over them, and then setting the length of the array (count) to k, the number that passed the elimination.

Thanks Paul i get it now =)
+1  A: 

It's eliminating any points that have drifted more than 5 pixels (5*5=25). k is being used to track the output index when points are deleted.

Mr Fooz
A: 

I manage to figure out the where the clearing of points are done. As frame loops the new points are reflected on the new frame and the new frame refreshes the previous.