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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
=
"""
ByteTrack tracker implementation.
Use `ByteTrack()` to initialize and `update()` to process frames.
**Usage Example:**
```python
from trackforge import ByteTrack
import numpy as np
# Initialize tracker with default parameters
tracker = ByteTrack(
track_thresh=0.5,
track_buffer=30,
match_thresh=0.8,
det_thresh=0.6
)
# Simulated detections: [x, y, w, h]
# Format: (box, score, class_id)
detections = [
([100.0, 100.0, 50.0, 100.0], 0.9, 0),
([200.0, 200.0, 60.0, 120.0], 0.85, 0)
]
# Update tracker
tracks = tracker.update(detections)
# Process active tracks
for track in tracks:
track_id, box, score, class_id = track
print(f"Track ID: {track_id}, Box: {box}")
```
"""
"""
Initialize the ByteTrack tracker.
Args:
track_thresh (float, optional): High confidence detection threshold. Defaults to 0.5.
track_buffer (int, optional): Number of frames to keep lost tracks alive. Defaults to 30.
match_thresh (float, optional): IoU matching threshold. Defaults to 0.8.
det_thresh (float, optional): Initialization threshold. Defaults to 0.6.
"""
...
"""
Update the tracker with detections from the current frame.
Args:
output_results (list): A list of detections, where each detection is a tuple of
([x, y, w, h], score, class_id).
Returns:
list: A list of active tracks, where each track is a tuple of
(track_id, [x, y, w, h], score, class_id).
"""
...
"""
SORT (Simple Online and Realtime Tracking) tracker implementation.
A simple yet effective multi-object tracker using Kalman filtering and IoU matching.
**Usage Example:**
```python
from trackforge import Sort
# Initialize tracker with default parameters
tracker = Sort(max_age=1, min_hits=3, iou_threshold=0.3)
# Simulated detections: [x, y, w, h]
# Format: (box, score, class_id)
detections = [
([100.0, 100.0, 50.0, 100.0], 0.9, 0),
([200.0, 200.0, 60.0, 120.0], 0.85, 0)
]
# Update tracker
tracks = tracker.update(detections)
# Process confirmed tracks
for track in tracks:
track_id, box, score, class_id = track
print(f"Track ID: {track_id}, Box: {box}")
```
"""
"""
Initialize the SORT tracker.
Args:
max_age (int, optional): Maximum frames to keep track without detection. Defaults to 1.
min_hits (int, optional): Minimum hits before track is confirmed. Defaults to 3.
iou_threshold (float, optional): IoU threshold for matching. Defaults to 0.3.
"""
...
"""
Update the tracker with detections from the current frame.
Args:
detections (list): A list of detections, where each detection is a tuple of
([x, y, w, h], score, class_id).
Returns:
list: A list of confirmed tracks, where each track is a tuple of
(track_id, [x, y, w, h], score, class_id).
"""
...
"""
A confirmed track from the DeepSort tracker.
Attributes:
track_id (int): Unique track identifier.
tlwh (List[float]): Bounding box in TLWH format [top, left, width, height].
score (float): Detection confidence score.
class_id (int): Object class identifier.
"""
:
:
:
:
"""
Deep SORT tracker implementation with appearance feature matching.
Deep SORT extends SORT by adding appearance descriptors (embeddings) for
improved re-identification and reduced ID switches.
**Usage Example:**
```python
from trackforge import DeepSort
import cv2
import torch
import torchvision.models as models
import torchvision.transforms as T
from PIL import Image
# Initialize tracker
tracker = DeepSort(
max_age=70,
n_init=3,
max_iou_distance=0.7,
max_cosine_distance=0.2,
nn_budget=100
)
# Load an embedder (e.g., ResNet18)
model = models.resnet18(weights=models.ResNet18_Weights.DEFAULT)
model.fc = torch.nn.Identity()
model.eval()
transform = T.Compose([
T.Resize((128, 64)),
T.ToTensor(),
T.Normalize(mean=[0.485, 0.456, 0.406], std=[0.229, 0.224, 0.225]),
])
# For each frame:
# 1. Get detections from your detector
detections = [
([100.0, 100.0, 50.0, 100.0], 0.9, 0),
([200.0, 200.0, 60.0, 120.0], 0.85, 0)
]
# 2. Extract appearance embeddings for each detection
embeddings = [[0.1, 0.2, ...], [0.3, 0.4, ...]] # 512-dim vectors
# 3. Update tracker
tracks = tracker.update(detections, embeddings)
# 4. Process tracks
for track in tracks:
print(f"ID: {track.track_id}, Box: {track.tlwh}")
```
"""
"""
Initialize the Deep SORT tracker.
Args:
max_age (int, optional): Maximum frames to keep track without detection. Defaults to 70.
n_init (int, optional): Minimum consecutive detections to confirm a track. Defaults to 3.
max_iou_distance (float, optional): Max IoU distance for matching. Defaults to 0.7.
max_cosine_distance (float, optional): Max cosine distance for appearance matching. Defaults to 0.2.
nn_budget (int, optional): Maximum appearance feature library size per track. Defaults to 100.
"""
...
"""
Update the tracker with detections and their appearance embeddings.
Args:
detections (list): A list of detections, where each detection is a tuple of
([x, y, w, h], score, class_id).
embeddings (list): A list of appearance embeddings (e.g., 512-dim vectors)
corresponding to each detection. Must have same length as detections.
Returns:
list[DeepSortTrack]: A list of confirmed tracks with track_id, tlwh, score, class_id.
Raises:
ValueError: If the number of detections and embeddings don't match.
"""
...