Skip to content

trackforge / trackers / sort


Module sort

SORT: Simple Online and Realtime Tracking

This module implements the SORT (Simple Online and Realtime Tracking) algorithm.

Algorithm Overview

SORT is a simple yet effective multi-object tracking algorithm that combines:

  • Kalman Filtering for motion prediction
  • Hungarian Algorithm for data association using IoU (Intersection over Union)

Key Features

  • Real-time performance: Designed for speed with minimal computational overhead
  • No appearance features: Uses only bounding box information
  • Simple track management: Tracks are created, confirmed, and deleted based on hit/miss counts

Parameters

Parameter Default Description
max_age 1 Maximum frames to keep a track without detection
min_hits 3 Minimum consecutive hits before track is confirmed
iou_threshold 0.3 Minimum IoU for matching detection to track

References

Simple Online and Realtime Tracking Alex Bewley, Zongyuan Ge, Lionel Ott, Fabio Ramos, Ben Upcroft IEEE International Conference on Image Processing (ICIP), 2016 arXiv:1602.00763

Quick Reference

Item Kind Description
Sort struct SORT (Simple Online and Realtime Tracking) tracker.
SortParams struct Settings for [Sort].
SortTrack struct A single track in SORT.
SortTrackState type Track state enumeration for SORT.

Types

Sort

struct Sort {
    // [REDACTED: Private Fields]
}

SORT (Simple Online and Realtime Tracking) tracker.

Example

use trackforge::trackers::sort::Sort;

// Initialize tracker
let mut tracker = Sort::new(1, 3, 0.3);

// Simulated detections: (tlwh_box, score, class_id)
let detections = vec![
    ([100.0, 100.0, 50.0, 100.0], 0.9, 0),
    ([200.0, 200.0, 60.0, 120.0], 0.85, 0),
];

// Update tracker
let tracks = tracker.update(detections);

for track in tracks {
    println!("Track ID: {}, Box: {:?}", track.track_id, track.tlwh);
}

Implementations

fn new(max_age: usize, min_hits: usize, iou_threshold: f32) -> Self

Create a new SORT tracker instance.

# Arguments

Argument Description
max_age Maximum frames to keep a track without detection (default: 1).
min_hits Minimum consecutive hits before track is confirmed (default: 3).
iou_threshold Minimum IoU for matching detection to track (default: 0.3).

fn from_params(params: SortParams) -> Self

Create a SORT tracker from a SortParams.

fn update(&mut self, detections: Vec<([f32; 4], f32, i64)>) -> Vec<SortTrack>

Update the tracker with detections from the current frame.

# Arguments

Argument Description
detections A vector of detections, where each detection is (TLWH_Box, Score, ClassID).

# Returns

A vector of confirmed tracks.

Trait Implementations

impl Default for Sort

fn default() -> Self

fn to_subset(&self) -> Option<SS>

fn is_in_subset(&self) -> bool

fn to_subset_unchecked(&self) -> SS

fn from_subset(element: &SS) -> SP

impl Tracker for Sort
  • type Track = SortTrack

fn update(&mut self, detections: Vec<crate::traits::Detection>) -> Vec<SortTrack>

SortParams

struct SortParams {
    pub common: crate::trackers::common::CommonParams,
    pub iou_threshold: f32,
}

Settings for Sort.

The shared lifecycle fields live in CommonParams; the field below is specific to SORT. Build it with default and tweak what you need, then pass it to [Sort::from_params].

Fields

Name Type Description
common crate::trackers::common::CommonParams Shared lifecycle settings, max_age and min_hits.
iou_threshold f32 Smallest IoU overlap that still counts as the same object between a track and a detection. This is a minimum IoU, so higher is stricter and separates touching objects more readily, while lower tolerates loose boxes but risks swapping ids.

Trait Implementations

impl Clone for SortParams

fn clone(&self) -> SortParams

impl Copy for SortParams
impl Debug for SortParams

fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result

impl Default for SortParams

fn default() -> Self

impl PartialEq for SortParams

fn eq(&self, other: &SortParams) -> bool

fn to_subset(&self) -> Option<SS>

fn is_in_subset(&self) -> bool

fn to_subset_unchecked(&self) -> SS

fn from_subset(element: &SS) -> SP

SortTrack

struct SortTrack {
    pub tlwh: [f32; 4],
    pub score: f32,
    pub class_id: i64,
    pub track_id: u64,
    pub state: SortTrackState,
    pub hits: usize,
    pub time_since_update: usize,
    pub age: usize,
    pub det_ind: Option<usize>,
    // [REDACTED: Private Fields]
}

A single track in SORT.

Fields

Name Type Description
tlwh [f32; 4] Bounding box in TLWH (Top-Left-Width-Height) format.
score f32 Detection confidence score.
class_id i64 Class ID of the object.
track_id u64 Unique track ID.
state SortTrackState Current tracking state.
hits usize Number of consecutive hits (matched detections).
time_since_update usize Number of consecutive misses (no matched detection).
age usize Total age of the track in frames.
det_ind Option<usize> Index into the current frame's detections of the detection that most recently created or updated this track. None if never matched.

Implementations

fn new(tlwh: [f32; 4], score: f32, class_id: i64, kf: &KalmanFilter, track_id: u64) -> Self

Create a new track from a detection.

fn predict(&mut self, kf: &KalmanFilter)

Predict the next state using Kalman filter.

fn mark_deleted(&mut self)

Mark track as deleted.

fn is_confirmed(&self) -> bool

Check if track should be confirmed based on min_hits.

Trait Implementations

impl Clone for SortTrack

fn clone(&self) -> SortTrack

impl Debug for SortTrack

fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result

fn to_subset(&self) -> Option<SS>

fn is_in_subset(&self) -> bool

fn to_subset_unchecked(&self) -> SS

fn from_subset(element: &SS) -> SP

SortTrackState

type SortTrackState = crate::trackers::common::TrackState;

Track state enumeration for SORT.

Alias of the shared TrackState.