How to count how many times a point was tracked with opticalFlow

asked 2019-04-23 22:31:38 -0500

Christoph gravatar image


I'm trying to color points that have been tracked by calcOpticalFlowPyrLK based on how long they have been tracked to mark some "stable" points. So e.g. points that have been tracked in 3 less than 10 consecutive pictures shall be marked in blue while points that have been tracked in more than 10 consecutive pictures shall be marked in green. But I'm stucking on how to count this (intensity shall be my counter). I have tried this:

calcOpticalFlowPyrLK(img_1, img_2, points1, points2, status, err, winSize, 3, termcrit, 0, 0.001);

int indexCorrection = 0;
for (int i = 0; i<status.size(); i++)
    Point2f pt = - indexCorrection);
    if ( i ) == 0 ) {
        points1.erase( points1.begin() + (i - indexCorrection) );
        points2.erase( points2.begin() + (i - indexCorrection) );
        intensity.erase( intensity.begin() + (i - indexCorrection) );
    else i - indexCorrection )++;

Bit I still see points that are marked in green although these are noisy points that appear and disappear really fast (and I have chosen a really high threshold), Do you have any ideas or know a better solution for this problem?

edit retag flag offensive close merge delete


what's the point of doing this ? what are you trying to achieve ?

berak gravatar imageberak ( 2019-04-24 01:38:51 -0500 )edit

Hi, I'm trying to 'classify' the tracked features based on how long they have been tracked. It's just for visualization.

Christoph gravatar imageChristoph ( 2019-04-24 06:17:53 -0500 )edit

^^ yea, that's the part i don't understand !

berak gravatar imageberak ( 2019-04-24 06:41:02 -0500 )edit

It helps to identify new tracked features and some kind of 'stable' features. So in a video stream if you find a feature in img_n and img_(n+1) you will get a positiv result from the optical flow algorithm. But this could still be an artifact caused by noise. But if you track this feature in e.g. 100 consecutive frames I would suggest that this feature seems to be stable and maybe more reliable for subsequent algorithms.

Christoph gravatar imageChristoph ( 2019-04-24 07:46:55 -0500 )edit