A multi-object tracking library for Swift, powered by a Rust-based tracking engine.
Provides three tracking algorithms:
- ByteTracker — Two-stage matching using high and low-confidence detections
- BoostTracker — IoU + Mahalanobis distance + shape similarity (supports BoostTrack+/++ modes)
- OCSort — Observation-centric online smoothing with velocity direction consistency
- macOS 12+
- iOS 15+
- Swift 5.9+
Add the following to your Package.swift:
dependencies: [
.package(url: "https://github.com/mprg-smilab/JTrackers.git", from: "0.4.1"),
],
targets: [
.target(
name: "YourTarget",
dependencies: ["JTrackers"]
),
]In Xcode, go to File → Add Package Dependencies... and enter the repository URL above.
- Initialize a tracker
- Pass detections (
[TrackedObject]) toupdate()for each frame - Use the returned
trackIdto track each object across frames
import JTrackers
// 1. Create a tracker
let tracker = ByteTracker()
// 2. Create detections (e.g. output from an object detection model)
let detections = [
TrackedObject(x: 10, y: 20, width: 100, height: 200, prob: 0.9),
TrackedObject(x: 300, y: 400, width: 80, height: 160, prob: 0.8),
]
// 3. Update the tracker and get track IDs
let results = try tracker.update(detections).get()
for obj in results {
print("Track ID: \(obj.trackId ?? -1), bbox: (\(obj.x), \(obj.y), \(obj.width), \(obj.height))")
}let tracker = ByteTracker(
frameRate: 30,
trackBuffer: 30,
trackThresh: 0.5,
highThresh: 0.6,
matchThresh: 0.8
)let tracker = BoostTracker(
detThresh: 0.5,
iouThreshold: 0.3,
maxAge: 30,
minHits: 3
)
// Enable BoostTrack++ mode
let tracker = BoostTracker(enableBoostPlusPlus: true)let tracker = OCSort(
detThresh: 0.5,
maxAge: 30,
minHits: 3,
iouThreshold: 0.3,
deltaT: 3,
inertia: 0.2,
useByte: false
)Full API documentation is available at: https://kadu-v.github.io/JTrackers/documentation/jtrackers/
See LICENSE for details.