Tracking
Source: CS1674 Ch.9. Track objects across frames using (1) KLT feature tracking, (2) Mean-Shift mode-seeking, and (3) Kalman filtering for prediction under occlusion.
1. KLT Tracking (Kanade–Lucas–Tomasi)
History: Lucas & Kanade (1981, LK optical flow estimator) + Tomasi & Kanade (1991, good features to track). KLT = Kanade–Lucas–Tomasi.
1.1 KLT tracking algorithm
- Find corners inside the object's bounding box / segmentation.
- For each corner, compute displacement
to the next frame using the Lucas–Kanade estimator; update corner positions. - Use RANSAC (or similar) to estimate a geometric transformation (translation / affine / homography) from the matched points.
- Apply that transformation to the object's bounding box / segmentation.
- (Optional) add more corner points every
frames. - Repeat 2–5 to produce trajectories of the bounding box / segmentation over time.
With enough matched features across two images, tracking becomes accurate; tracking-by-detection-and-matching is also valid (detect + match + geometric verification per frame).
2. Mean-Shift Tracking (Fukunaga & Hostetler 1975)
A mode-seeking algorithm: find the region of highest density of a feature distribution.
2.1 Intuition
Repeatedly: pick a point → draw a window → compute the (weighted) mean of the data in the window → shift the window to that mean → repeat until convergence. The window climbs the density gradient to the nearest mode.
2.2 Applied to tracking
When the object moves between frames, the window (placed at the previous location) no longer focuses on the dense region; mean-shift refines it to the best candidate location.
Algorithm:
- Initialize — in frame 1, select the target region; compute a color histogram, weighting pixels near the center more (via a kernel function, e.g., Epanechnikov/Gaussian).
- Start tracking — in the next frame, place the window at the previous object location.
- Compute weights — compare each pixel's appearance (histogram/descriptor) to the target; assign higher weights to pixels that match the target better.
- Shift the window — compute the weighted average position (the mean-shift vector) of matching pixels; move the window there.
- Iterate steps 3–4 until the window position converges (stops moving).
Why it works: there is an implicit objective (the density/Bhattacharyya cost); each shift step performs gradient ascent on it. It is robust to small deformations and partial appearance change.
3. Kalman Filter (Prediction under Occlusion)
When objects are heavily occluded, detection-and-matching fails. Tracking by prediction takes over: the Kalman filter predicts the next state from past motion and corrects it using residuals between prediction and observation.
3.1 State-space model (linear, Gaussian)
- State equation (prediction):
, - Observation equation (update):
,
where
3.2 Two-step recursion
Predict:
Update (with innovation
The Kalman gain
4. Summary
| Method | Type | Best when |
|---|---|---|
| KLT | Feature-based | Good corners, small motion, need trajectories |
| Mean-Shift | Mode-seeking (histogram) | Appearance described by color/descriptor density |
| Kalman | Predictive filter | Occlusion / missing detections; smooth motion |
Track by: detecting good features (KLT), seeking the appearance mode (Mean-Shift), or predicting-through-occlusion (Kalman). Choose by whether you have reliable detections and how noisy the motion is.
5. Mean-Shift: The Math
The mean-shift vector points toward the mode of the density estimated with a kernel
Iterate
Why it tracks
There is an implicit objective (the density/Bhattacharyya cost); each shift step ascends it. It is robust to small deformations and partial appearance change because it only needs the mode of matching pixels, not an exact template.
6. Kalman Filter: A Concrete 2D Example
Model a point moving with constant velocity in 2D. State
- Transition:
, . - Observation: we only see position,
, .
Run predict → update each frame. During an occlusion (no detection), skip the update and keep predicting with
7. Comparison & When to Use Each
| Method | Needs | Best for | Failure mode |
|---|---|---|---|
| KLT | good corners, small motion | pointwise trajectories, SLAM | drifts, dies on no-feature regions |
| Mean-Shift | appearance histogram | single-object, color/texture mode | loses target on fast motion, similar distractors |
| Kalman | motion model | smoothing through occlusion | wrong model → divergence |
Multiple Object Tracking (MOT)
Combine detection + data association (Hungarian assignment / IoU/graph matching) across frames, often with a Kalman filter per track to bridge missed detections.
Applications
Surveillance, sports analytics, autonomous driving (track cars/pedestrians), AR/VR, robotics manipulation, video editing (rotoscoping).
Rule of thumb: use KLT for sparse feature trajectories, Mean-Shift for single-object appearance tracking, and Kalman (or a particle filter) when you must predict through missing/occluded observations.
8. Particle Filter (Optional Extension)
When the motion/observation model is non-linear/non-Gaussian, the Kalman filter's Gaussian assumption breaks. A particle filter represents the posterior over states by a set of weighted samples ("particles"):
- Predict: propagate each particle by the motion model + noise.
- Update: weight each particle by how well it matches the observation (likelihood).
- Resample: draw new particles proportional to weights.
This handles multi-modal distributions (e.g., when a target could be in either of two corridors) that a single Gaussian Kalman filter cannot represent.
9. Evaluating Trackers
- MOTA / MOTP (Multiple Object Tracking Accuracy/Precision): aggregate over frames; MOTA counts misses, false positives, and ID switches; MOTP measures bounding-box overlap.
- Track continuity: penalize ID switches (a track changing its object identity).
- Robustness: performance under occlusion, fast motion, and distractors.
Tracking is fundamentally state estimation over time; KLT, Mean-Shift, and Kalman/particle filters are three tools trading off speed, appearance modeling, and robustness to missing data.