Skip to main content
The tracking module provides various algorithms for tracking objects across video frames, from classical methods like Kalman filtering to modern deep learning-based approaches.

Tracker Base Class

Base abstract class for long-term object trackers.

init

Initialize the tracker with a known bounding box that surrounds the target.
image
InputArray
required
The initial frame containing the object to track.
boundingBox
const Rect&
required
The initial bounding box surrounding the target object.

update

Update the tracker and find the new most likely bounding box for the target.
image
InputArray
required
The current frame to process.
boundingBox
Rect&
required
Output parameter for the new target location. Updated only if the function returns true.
Returns: true if the target was located, false if the tracker cannot locate the target. Note that false does not necessarily mean the tracker has failed—the target may be temporarily out of view.

KalmanFilter

Implements a standard Kalman filter for state estimation.

Constructor

dynamParams
int
required
Dimensionality of the state vector.
measureParams
int
required
Dimensionality of the measurement vector.
controlParams
int
Dimensionality of the control vector. Default: 0 (no control).
type
int
Type of the created matrices. Should be CV_32F or CV_64F. Default: CV_32F.

predict

Computes a predicted state.
control
const Mat&
Optional input control vector.
Returns: Reference to the predicted state vector.

correct

Updates the predicted state from the measurement.
measurement
const Mat&
required
The measured system parameters.
Returns: Reference to the corrected state vector.
The Kalman filter operates in two steps: prediction (using the system model) and correction (using measurements). The filter maintains estimates of the state and its uncertainty through covariance matrices.

Example

TrackerMIL

Multiple Instance Learning (MIL) tracker that trains a classifier online to separate object from background.
MIL avoids the drift problem for robust tracking. The implementation is based on “Visual Tracking with Online Multiple Instance Learning” by Babenko et al.

Example

TrackerGOTURN

Generic Object Tracking Using Regression Networks - a CNN-based tracker trained offline.
GOTURN is much faster than online-training CNN trackers due to its offline training approach. It handles viewpoint changes, lighting changes, and deformations well, but does not handle occlusions. Requires pre-trained models (goturn.prototxt and goturn.caffemodel).

Example

TrackerDaSiamRPN

Deep learning-based tracker using Siamese Region Proposal Networks.
getTrackingScore()
float
Returns the tracking confidence score for the current frame.

TrackerNano

Super lightweight DNN-based tracker with model size of only 1.9 MB.
Nano tracker is extremely lightweight and fast due to its special model structure. Requires two models: one for feature extraction (backbone) and another for localization (neckhead).

TrackerVit

Vision Transformer (ViT) based tracker, extremely lightweight at approximately 767KB.
meanvalue
Scalar
Mean values for image preprocessing. Default: (0.485, 0.456, 0.406)
stdvalue
Scalar
Standard deviation values for image preprocessing. Default: (0.229, 0.224, 0.225)
tracking_score_threshold
float
Minimum confidence threshold for tracking. Default: 0.20

Comparison of Trackers

MIL (Multiple Instance Learning)
  • Pros: Robust, handles appearance changes
  • Cons: Slower than modern methods
  • Use case: General purpose tracking