1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
//! [](https://crates.io/crates/trackforge)
//! [](https://docs.rs/trackforge)
//! [](https://github.com/onuralpszr/trackforge/actions/workflows/CI.yml)
//! [](https://opensource.org/licenses/MIT)
//! [](https://blog.rust-lang.org/2025/05/15/Rust-1.88.0/)
//!
//! Trackforge is a unified, high-performance computer vision tracking library implemented in
//! Rust and exposed as a Python package via PyO3.
//!
//! It provides four production-ready multi-object tracking algorithms built on a shared
//! 8-dimensional Kalman filter with state `[x, y, a, h, vx, vy, va, vh]`, where `(x, y)`
//! is the bounding-box centre, `a` the aspect ratio, and `h` the height.
//!
//! # Choose a Tracker
//!
//! | Tracker | Appearance Features | Matching Strategy | Best For |
//! |---------|-------------------|-------------------|----------|
//! | [`sort`] | None | IoU only | Simple scenes, maximum speed |
//! | [`byte_track`] | None | IoU two-stage | Crowded scenes, low-confidence detections |
//! | [`ocsort`] | None | IoU + velocity correction | Scenes with frequent occlusions |
//! | [`deepsort`] | Re-ID embeddings | Appearance + IoU | Long occlusions, dense crowds |
//!
//! # SORT
//!
//! Simple Online and Realtime Tracking. Pure IoU matching with a Kalman filter.
//! Fastest option with minimal configuration.
//!
//! ```rust
//! use trackforge::trackers::sort::Sort;
//!
//! // max_age=1, min_hits=3, iou_threshold=0.3
//! let mut tracker = Sort::new(1, 3, 0.3);
//!
//! let detections = vec![
//! ([100.0_f32, 100.0, 50.0, 100.0], 0.9_f32, 0_i64),
//! ];
//!
//! let tracks = tracker.update(detections);
//! for t in &tracks {
//! println!("ID: {}, Box: {:?}", t.track_id, t.tlwh);
//! }
//! ```
//!
//! # ByteTrack
//!
//! Two-stage IoU matching that also associates low-confidence detections, recovering
//! objects that are temporarily occluded or partially out of frame.
//!
//! ```rust
//! use trackforge::trackers::byte_track::ByteTrack;
//!
//! // track_thresh=0.5, track_buffer=30, match_thresh=0.8, det_thresh=0.6
//! let mut tracker = ByteTrack::new(0.5, 30, 0.8, 0.6);
//!
//! let detections = vec![
//! ([100.0_f32, 100.0, 50.0, 100.0], 0.9_f32, 0_i64),
//! ([200.0_f32, 200.0, 60.0, 120.0], 0.85_f32, 0_i64),
//! ];
//!
//! let tracks = tracker.update(detections);
//! for t in &tracks {
//! println!("ID: {}, Box: {:?}, Score: {:.2}", t.track_id, t.tlwh, t.score);
//! }
//! ```
//!
//! # DeepSORT
//!
//! Augments IoU matching with Re-ID appearance embeddings for reliable re-identification
//! across long occlusions. Requires an [`AppearanceExtractor`] implementation that produces
//! a feature vector for each detected crop.
//!
//! ```rust,ignore
//! use trackforge::trackers::deepsort::DeepSort;
//! use trackforge::traits::AppearanceExtractor;
//! use trackforge::types::BoundingBox;
//! use image::DynamicImage;
//!
//! struct MyExtractor;
//!
//! impl AppearanceExtractor for MyExtractor {
//! fn extract(
//! &self,
//! image: &DynamicImage,
//! boxes: &[BoundingBox],
//! ) -> Result<Vec<Vec<f32>>, Box<dyn std::error::Error>> {
//! // Return one embedding vector per bounding box
//! Ok(boxes.iter().map(|_| vec![0.0_f32; 128]).collect())
//! }
//! }
//!
//! // max_age=70, n_init=3, max_iou_distance=0.7, max_cosine_distance=0.2, nn_budget=100
//! let mut tracker = DeepSort::new(MyExtractor, 70, 3, 0.7, 0.2, 100);
//!
//! let frame = DynamicImage::new_rgb8(640, 480);
//! let detections = vec![
//! (BoundingBox { x: 100.0, y: 100.0, width: 50.0, height: 100.0 }, 0.9_f32, 0_i64),
//! ];
//!
//! let tracks = tracker.update(&frame, &detections).unwrap();
//! for t in &tracks {
//! println!("ID: {}, Box: {:?}", t.track_id, t.to_tlwh());
//! }
//! ```
//!
//! # OC-SORT
//!
//! Observation-Centric SORT. Extends SORT with velocity correction (OCM) and Kalman filter
//! re-update on re-association (ORU), making it robust to brief occlusions without appearance
//! features.
//!
//! ```rust
//! use trackforge::trackers::ocsort::OcSort;
//!
//! // max_age=30, min_hits=3, iou_threshold=0.3, delta_t=3, inertia=0.2
//! let mut tracker = OcSort::new(30, 3, 0.3, 3, 0.2);
//!
//! let detections = vec![
//! ([100.0_f32, 100.0, 50.0, 100.0], 0.9_f32, 0_i64),
//! ];
//!
//! let tracks = tracker.update(detections);
//! for t in &tracks {
//! println!("ID: {}, Box: {:?}", t.track_id, t.tlwh);
//! }
//! ```
//!
//! [`sort`]: trackers::sort
//! [`byte_track`]: trackers::byte_track
//! [`ocsort`]: trackers::ocsort
//! [`deepsort`]: trackers::deepsort
//! [`AppearanceExtractor`]: traits::AppearanceExtractor
use *;
/// The Python module for Trackforge.