How to count how many times a point was tracked with opticalFlow
Hello,
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 = points2.at(i - indexCorrection);
if ( status.at( i ) == 0 ) {
points1.erase( points1.begin() + (i - indexCorrection) );
points2.erase( points2.begin() + (i - indexCorrection) );
intensity.erase( intensity.begin() + (i - indexCorrection) );
indexCorrection++;
}
else
intensity.at( 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?
what's the point of doing this ? what are you trying to achieve ?
Hi, I'm trying to 'classify' the tracked features based on how long they have been tracked. It's just for visualization.
^^ yea, that's the part i don't understand !
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.