Object tracking

A description and implementation of Median Flow

By Morten Høfft - March 2, 2014

Object tracking in videos can be done in many ways. One that performs well, and is simple to understand, is the Median Flow tracker. I have implemented a javascript demo, an interactive example and written a short description.

Click and drag to select your interest area. Faces are a good choice.


requires your webcam


Given a point in one image, the Lucas-Kanade tracking algorithm will attempt to locate the same point in the following image. This is no trivial matter and so the points are likely to slide of target. Especially if they are not carefuly selected. This means that we quickly get a cacaphony of points, going of in many directions. Further we are typically interested in tracking an area/object and not a point.

Drag points to see changes




{{k.label}} :
{{item | number:2}}

Median Flow solution

We select an area we are interested in. We then intiate a grid of points we can track using Lucas-Kanade point tracking. The question is how we update our area of interst based on the - often conflicting - motion estimates given by the LK point tracker. Median Flow suggest taking the median of the vectors. That is: list the movement of the points on the x-axis and take the median. Same for the y-axis. Scale is calculated by considering all pairs of points and meassuring the relative change in distance (distNew/distOld). Again the median is selected. This turns out to be a fairly robust estimate that compares with the best. Further it has the benefit of being simple to understand and implement.

Above example illustrates how values are calculated based on the point movement. To see changes in the medians you can drag the points (something the point tracker would normally do).