Skip to main content

sightloom_tracking/
config.rs

1//! `ByteTrack` configuration.
2
3use crate::TrackError;
4
5/// Runtime parameters for [`crate::ByteTracker`].
6#[derive(Clone, Copy, Debug, PartialEq)]
7pub struct ByteTrackConfig {
8    /// Detections at or above this score enter high-confidence matching.
9    pub track_high_thresh: f32,
10    /// Detections at or above this score may create new tracks.
11    pub track_activation_thresh: f32,
12    /// Floor for low-confidence second-stage matching.
13    pub track_low_thresh: f32,
14    /// Minimum intersection-over-union required for a valid match.
15    pub match_thresh: f32,
16    /// Frames a lost track is retained for re-association.
17    pub max_time_lost: u32,
18    /// When true, only same-class detections may match a track.
19    pub class_aware: bool,
20}
21
22impl Default for ByteTrackConfig {
23    fn default() -> Self {
24        Self {
25            track_high_thresh: 0.5,
26            track_activation_thresh: 0.6,
27            track_low_thresh: 0.1,
28            match_thresh: 0.8,
29            max_time_lost: 30,
30            class_aware: false,
31        }
32    }
33}
34
35impl ByteTrackConfig {
36    /// Validates finite thresholds in `0.0..=1.0` and non-zero lost buffer.
37    ///
38    /// # Errors
39    ///
40    /// Returns [`TrackError::InvalidConfig`] when any field is out of range.
41    pub fn validate(self) -> Result<Self, TrackError> {
42        let thresholds = [
43            self.track_high_thresh,
44            self.track_activation_thresh,
45            self.track_low_thresh,
46            self.match_thresh,
47        ];
48        for value in thresholds {
49            if !value.is_finite() || !(0.0..=1.0).contains(&value) {
50                return Err(TrackError::InvalidConfig);
51            }
52        }
53        if self.track_low_thresh > self.track_high_thresh {
54            return Err(TrackError::InvalidConfig);
55        }
56        if self.max_time_lost == 0 {
57            return Err(TrackError::InvalidConfig);
58        }
59        Ok(self)
60    }
61}