Lktrack optical flow showing poor performance with fast object movement

Hi all,

I’m working on a problem where I need to estimate the velocity of objects in a scene. The camera is static, and the objects move strictly perpendicular to the camera, so optical flow seems like a good way to achieve this.

I’ve run some tests using the from the latest opencv version from Github (samples/python/

It seems like lktrack performs very well on relatively slow-moving objects in the scene, reliably detecting corners and creating tracks. Here’s an example.

Once the movement is sped up, however, it completely fails to consistently detect corners and create the tracks. You can see an example of this here.

I’ve played with both the lktrack parameters as well as the goodfeaturestotrack() parameters with no improvement. When applying a binary threshold to the video, the lktrack example actually works for the fast-moving example. This suggests that goodfeaturestotrack() somehow struggles to detect fast-moving features unless the contrast is very high. I’m confused by this because the videos I’m using as input are computer generated and contain no motion blur. I would therefore assume that corner detection should work equally well, whether the object moves fast or slow.

The other odd behavior is that the images is filled up with tracking points that don’t actually move.

Any suggestions on how to improve the performance of lktrack for fast movment would be highly appreciated.


LK is slow. can’t be helped. use a different algorithm. perhaps look at DIS. it’s in OpenCV.

LK, being a pyramid scheme, has a maxLevel parameter. you should get familiar with the API and the algorithm.

Thanks @crackwitz ! Increasing the pyramid count actually helped in getting more consistent tracking. I read the documentation and a bunch of tutorials, but this wasn’t obvious to me. I’m not so concerned about speed and more about accuracy so this approach might ok.

LK also sucks quality-wise compared to DIS. I don’t know what DIS does to manage that.