Advanced level · Module 4: Object Tracking and Localization · Lesson 2 of 4
The Kalman Filter
Learners implement a constant-velocity Kalman filter in NumPy to smooth noisy positions and predict where an object will be next.
In this lesson you will
- Explain the predict and update steps
- Implement a constant-velocity Kalman filter
Key concepts
state (position, velocity)predict stepupdate stepprocess and measurement noiseKalman gain
The lesson
A Kalman filter keeps an estimate of an object's state (for example position and velocity) and its uncertainty. The predict step moves the state forward using a motion model; the update step corrects it with a new, noisy measurement, weighting each by its uncertainty through the Kalman gain.
With a constant-velocity model, the filter smooths jittery detections and predicts positions through short gaps when a detection is missed, which is exactly what trackers need.
Tuning the process noise (how much the motion can change) and measurement noise (how noisy detections are) trades smoothness against responsiveness. OpenCV also provides cv2.KalmanFilter.
Step by step
- Simulate a moving point with noisy measurements.
- Implement predict and update with NumPy matrices.
- Plot true, measured and filtered positions.
- Remove measurements for five frames and show the predictions.
Practice activity
Implement and tune a Kalman filter on simulated and real detection tracks.
Expected result: A filter that smooths noise and predicts through gaps, with tuning explained.
Check your understanding
-
What does the update step do?
Show answer
It corrects the predicted state using a new measurement.
-
What happens if measurement noise is set very high?
Show answer
The filter trusts predictions more and responds slowly to measurements.
Further learning
Taught live by an instructor — online or in person. Free course lessons are for self-study and do not lead to a certificate — see registration options.