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};
9pub mod 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 MockDetection {
27    /// Creates a new mock detection with the given bounding box, score, and label.
28    pub fn new(bbox: [f32; 4], score: f32, label: usize) -> Self {
29        Self { bbox, score, label }
30    }
31}
32
33impl DetectionBox for MockDetection {
34    fn bbox(&self) -> [f32; 4] {
35        self.bbox
36    }
37
38    fn score(&self) -> f32 {
39        self.score
40    }
41
42    fn label(&self) -> usize {
43        self.label
44    }
45}
46
47#[derive(Debug, Clone, Copy, PartialEq)]
48pub struct TrackInfo {
49    pub uuid: Uuid,
50    /// 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).
51    pub tracked_location: [f32; 4],
52    pub count: i32,
53    pub created: u64,
54    pub last_updated: u64,
55}
56
57#[derive(Debug, Clone, Copy, PartialEq)]
58pub struct ActiveTrackInfo<T: DetectionBox> {
59    pub info: TrackInfo,
60    /// The last raw box associated with the track. This is before any smoothing
61    /// introduced by the tracker
62    pub last_box: T,
63}
64
65pub trait Tracker<T: DetectionBox> {
66    fn update(&mut self, boxes: &[T], timestamp: u64) -> Vec<Option<TrackInfo>>;
67    fn get_active_tracks(&self) -> Vec<ActiveTrackInfo<T>>;
68}