trackforge / trackers / deepsort
Module deepsort
DeepSORT (Simple Online and Realtime Tracking with a Deep Association Metric) implementation.
This module provides a DeepSORT tracker that uses appearance features for more robust tracking.
Quick Reference
| Item | Kind | Description |
|---|---|---|
DeepSort |
struct | Deep SORT tracker implementation. |
Types
NearestNeighborDistanceMetric
A nearest neighbor distance metric for deep association.
Keeps a history of features (samples) for each target (track) and computes the minimum distance between a new feature and the stored history.
Implementations
Create a new distance metric.
# Arguments
| Argument | Description |
|---|---|
metric |
The distance metric to use (Euclidean or Cosine). |
matching_threshold |
Threshold for matching. |
budget |
Optional maximum number of samples to keep per track. |
Update the sample gallery with new features.
# Arguments
| Argument | Description |
|---|---|
features |
Map from track_id to a list of new features. |
active_targets |
List of track IDs that are currently active (confirmed). Sample galleries for inactive targets will be removed. |
Compute the distance matrix between tracks and detections.
# Arguments
| Argument | Description |
|---|---|
features |
A map of detection indices to their feature vectors (usually we pass a list of features corresponding to detections). |
targets |
List of track IDs to compare against. |
# Returns
An n_targets x n_features matrix of distances.
Trait Implementations
Track
struct Track {
pub track_id: u64,
pub class_id: i64,
pub hits: usize,
pub age: usize,
pub time_since_update: usize,
pub state: TrackState,
pub mean: crate::utils::kalman::StateVector,
pub covariance: crate::utils::kalman::CovarianceMatrix,
pub score: f32,
pub features: Vec<Vec<f32>>,
// [REDACTED: Private Fields]
}
A single object track maintained by the DeepSORT tracker.
Fields
| Name | Type | Description |
|---|---|---|
track_id |
u64 |
Unique track identifier. |
class_id |
i64 |
Class label of the tracked object. |
hits |
usize |
Number of times this track has been matched to a detection. |
age |
usize |
Total frames since the track was created. |
time_since_update |
usize |
Frames elapsed since the last successful detection match. |
state |
TrackState |
Current life-cycle state. |
mean |
crate::utils::kalman::StateVector |
Kalman filter mean state [x, y, a, h, vx, vy, va, vh]. |
covariance |
crate::utils::kalman::CovarianceMatrix |
Kalman filter covariance matrix. |
score |
f32 |
Detection confidence of the last matched detection. |
features |
Vec<Vec<f32>> |
Appearance embeddings accumulated since the last metric-gallery flush. |
Implementations
fn new(mean: StateVector, covariance: CovarianceMatrix, track_id: u64, class_id: i64, n_init: usize, max_age: usize, score: f32, feature: Vec<f32>) -> Self
Convert TLWH to (x, y, a, h)
Convert (x, y, a, h) to TLWH
fn update(&mut self, kf: &KalmanFilter, detection: &MeasurementVector, score: f32, class_id: i64, feature: Vec<f32>)
Trait Implementations
DeepSortTracker
struct DeepSortTracker {
pub metric: crate::trackers::deepsort::nn_matching::NearestNeighborDistanceMetric,
pub max_age: usize,
pub n_init: usize,
pub tracks: Vec<crate::trackers::deepsort::track::Track>,
pub kf: crate::utils::kalman::KalmanFilter,
pub max_iou_distance: f32,
pub next_id: u64,
}
Implementations
fn new(metric: NearestNeighborDistanceMetric, max_age: usize, n_init: usize, max_iou_distance: f32) -> Self
Trait Implementations
DeepSort<E: AppearanceExtractor>
Deep SORT tracker implementation.
Wraps the tracker logic and appearance feature extraction.
Implementations
fn new(extractor: E, max_age: usize, n_init: usize, max_iou_distance: f32, max_cosine_distance: f32, nn_budget: usize) -> Self
Create a new Deep SORT tracker.
# Arguments
| Argument | Description |
|---|---|
extractor |
The appearance feature extractor. |
max_age |
Maximum frames to keep a track without detection. Default: 70. |
n_init |
Minimum hits to confirm a track. Default: 3. |
max_iou_distance |
Threshold for IoU matching. Default: 0.7. |
max_cosine_distance |
Threshold for cosine distance matching. Default: 0.2. |
nn_budget |
Maximum library size for appearance features. Default: 100. |
fn update(&mut self, image: &DynamicImage, detections: Vec<(BoundingBox, f32, i64)>) -> Result<Vec<Track>, Box<dyn Error>>
Update the tracker with new frame and detections.
# Arguments
| Argument | Description |
|---|---|
image |
The current video frame. |
detections |
List of (BoundingBox, Score, ClassID). |
# Returns
List of confirmed tracks.
Trait Implementations
Metric
Trait Implementations
TrackState
Lifecycle state of a track.
A track starts Tentative, becomes
Confirmed once it has accumulated enough matches, and
is Deleted when it ages out or fails confirmation.
Variants
Tentative
Newly created; not yet confirmed by enough matches.
Confirmed
Confirmed active track returned to callers.
Deleted
Marked for removal.
Trait Implementations