Rolling average
The main result of our detection is the three values of the polynomial fit, for each lane. Following the same principle of the previous section, we can deduce that they cannot change much between frames, so we could consider the average of some of the previous frames, to reduce noise.
There is a technique called the exponentially weighted moving average (or rolling average), which can be used to easily compute an approximate average on some of the last values of a stream of values.
Given beta
, a parameter greater than zero and typically close to one, the moving average can be computed like this:
moving_average = beta * prev_average + (1-beta)*new_value
As an indication, the number of frames that most affect the average is given by the following:
1 / (1 - beta)
So, beta = 0.9
would average 10 frames, and beta = 0.95
would average 20 frames.
This concludes the chapter. I invite you to check the full code on GitHub and to play around with it. You can...