Skip to main content

edgefirst_tracker/
lib.rs

1// SPDX-FileCopyrightText: Copyright 2025 Au-Zone Technologies
2// SPDX-License-Identifier: Apache-2.0
3
4use std::fmt::Debug;
5
6pub use uuid::Uuid;
7pub mod bytetrack;
8pub use bytetrack::{ByteTrack, ByteTrackBuilder};
9mod kalman;
10
11pub trait DetectionBox: Debug + Clone {
12    fn bbox(&self) -> [f32; 4];
13    fn score(&self) -> f32;
14    fn label(&self) -> usize;
15}
16
17/// Mock detection box for testing and examples
18#[derive(Debug, Clone, Copy)]
19#[doc(hidden)]
20pub struct MockDetection {
21    bbox: [f32; 4],
22    score: f32,
23    label: usize,
24}
25
26impl DetectionBox for MockDetection {
27    fn bbox(&self) -> [f32; 4] {
28        self.bbox
29    }
30
31    fn score(&self) -> f32 {
32        self.score
33    }
34
35    fn label(&self) -> usize {
36        self.label
37    }
38}
39
40#[derive(Debug, Clone, Copy, PartialEq)]
41pub struct TrackInfo {
42    pub uuid: Uuid,
43    /// This is the current tracked location of the object, which may be smoothed by the tracker. It is in XYXY format (xmin, ymin, xmax, ymax).
44    pub tracked_location: [f32; 4],
45    pub count: i32,
46    pub created: u64,
47    pub last_updated: u64,
48}
49
50#[derive(Debug, Clone, Copy, PartialEq)]
51pub struct ActiveTrackInfo<T: DetectionBox> {
52    pub info: TrackInfo,
53    /// The last raw box associated with the track. This is before any smoothing
54    /// introduced by the tracker
55    pub last_box: T,
56}
57
58pub trait Tracker<T: DetectionBox> {
59    fn update(&mut self, boxes: &[T], timestamp: u64) -> Vec<Option<TrackInfo>>;
60    fn get_active_tracks(&self) -> Vec<ActiveTrackInfo<T>>;
61}