Kalman filtering
Combine a predicted state with a noisy observation using their estimated uncertainties.
The latest measurement does not lie exactly on the extrapolated motion path.
The motion model predicts a location. The broad ellipse illustrates uncertainty after prediction.
The orange vector is the difference between the measurement and the predicted observation.
The corrected position moves 65% toward the measurement in this scalar-gain example. The smaller ellipse illustrates reduced uncertainty, not a full covariance calculation.
Apply a covariance-weighted correction.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Filter an editable sequence of normalized (x,y) measurements with a constant-velocity model. The image is a backdrop: orange measurements, mint estimates.
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Smooth position or velocity measurements and predict where a tracked object will appear next.
How it works
- 01Predict the next state and covariance through the motion model.
- 02Compare the measurement with the predicted observation.
- 03Apply a covariance-weighted correction.
corrected state = prediction + gain × measurement residual
What to tune
Set transitionMatrix, measurementMatrix, processNoiseCov and measurementNoiseCov to match the state and sensor model.
Where it breaks down
The basic filter assumes linear models and specified noise statistics. It estimates state, but does not detect the object or solve data association.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Lucas-Kanade optical flow
Follow selected points by finding the small displacement that best aligns each local patch.
Farneback dense optical flow
Estimate a displacement vector at every pixel using local polynomial approximations.
DIS dense optical flow
Combine fast patch alignment with spatial propagation and dense refinement.
Dual TV-L1 optical flow
Estimate flow with a robust data term and a total-variation smoothness penalty.