Kalman Filter Predicts Then Corrects
The Kalman filter tracks by predicting where the object should be from its motion, then splitting the difference between that prediction and the new measurement by trust.
Why Does This Exist?
Detections are noisy and intermittent. A detector jitters a box by a few pixels each frame, misses frames entirely during occlusion, and reports no velocity to aim with. Naive tracking that copies the last detection inherits all of that: jittery boxes and lost IDs behind every pillar.
The Kalman filter from 1960 is the optimal estimator for linear motion with Gaussian noise, and the workhorse motion model inside classical object tracking pipelines such as SORT, extended by multi-object tracking association and covered generally in object tracking. It keeps a running belief of position plus velocity with an uncertainty, predicts it forward each frame, and corrects it with each measurement weighted by relative trust. During occlusion there is no measurement, so it coasts on prediction until the object reappears.
Think of It Like This
Catching a ball with your eyes half closed
You watch a ball arc toward you, blink, and your brain keeps simulating the arc during the blink. When your eyes open, the ball sits slightly off from where you imagined, and you instantly revise. The longer the blink, the less you trust the simulation; the blurrier your vision, the less you trust your eyes.
Prediction is the simulation during the blink and the measurement is the bleary glimpse. Where it stops: your brain also replays spin, wind, and bounce, while the plain filter believes only straight-line motion with bell-curve noise, so sharp maneuvers need extra process noise or a richer model.
How It Actually Works
The state holds position and velocity, . Each step predicts forward with constant velocity, with unchanged, while uncertainty grows by process noise : coasting means getting less sure. A new measurement with noise arrives, and the gain splits the difference: state prediction , uncertainty . High chases measurements, low rides the model. With no detection the update is skipped, prediction repeats, and uncertainty compounds so the matching gate widens honestly.
Worked example
Predicted position , measurement , gain . The residual is . The update is , exactly halfway because both sides were trusted equally. At gain the same pair gives , chasing the sensor. Uncertainty after the -gain update is : halved by one trusted look. Coast two frames with no detection and grows twice by with no halving, which is why long occlusions return wide gates.
Code
The point of this snippet is the update rule, not a tracker: pure standard-library code recomputes the worked example at both gains.
def kalman_update(pred: float, measure: float, gain: float) -> float: return pred + gain * (measure - pred)
print(round(kalman_update(12.0, 12.5, 0.5), 2))# -> 12.25print(round(kalman_update(12.0, 12.5, 0.9), 2))# -> 12.45Gain lands exactly halfway at ; gain chases the measurement to . Real trackers compute the gain from and each frame instead of fixing it.
Watch Out For
Constant velocity lies during maneuvers
The model assumes velocity barely changes, so a sharp turn or sudden stop leaves predictions flying straight while the object is gone. The filter recovers once measurements return, but IDs may already have switched. If tracks swap at every turn, raise process noise or move to an interacting-multiple-model setup.
Tuning Q and R by feel
for motion surprise and for sensor slop decide everything, and hand-tuned values from one camera fail on another. The symptom is a tracker that is perfect on one video and lost on the next. Measure from the detector's real jitter on static scenes, then set from the fastest accelerations that must be followed.
The Quick Version
- The Kalman filter predicts position from velocity, then corrects with the measurement weighted by the gain.
- Prediction with measurement at gain lands exactly at .
- Uncertainty halves on a trusted update and compounds while coasting, so occlusion gates widen honestly.
- Optimal only for linear motion with Gaussian noise; maneuvers need more process noise.
- The motion core of SORT-style trackers; nonlinear cases graduate to particle filters.