norfair_rs/
lib.rs

1//! # Norfair - Object Tracking Library
2//!
3//! Rust port of the Python [norfair](https://github.com/tryolabs/norfair) library.
4//!
5//! Norfair is a customizable lightweight library for real-time multi-object tracking.
6//!
7//! ## Features
8//!
9//! - Kalman filter-based tracking with multiple filter implementations
10//! - Pluggable distance functions (Euclidean, IoU, custom)
11//! - Camera motion compensation
12//! - Re-identification (ReID) support
13//! - MOTChallenge metrics evaluation
14//!
15//! ## Example
16//!
17//! ```rust,ignore
18//! use norfair_rs::{Tracker, TrackerConfig, Detection, distance_by_name};
19//!
20//! // Create tracker
21//! let config = TrackerConfig::new(distance_by_name("euclidean"), 50.0);
22//! let mut tracker = Tracker::new(config).unwrap();
23//!
24//! // Process detections
25//! let detections = vec![Detection::new(vec![[100.0, 100.0]])];
26//! let tracked_objects = tracker.update(detections, 1, None);
27//! ```
28
29// Internal modules (ports of scipy, filterpy, numpy, motmetrics)
30pub(crate) mod internal;
31
32// Public modules
33pub mod camera_motion;
34pub mod detection;
35pub mod distances;
36pub mod filter;
37pub mod matching;
38pub mod metrics;
39pub mod tracked_object;
40pub mod tracker;
41pub mod utils;
42
43// Optional modules
44#[cfg(feature = "opencv")]
45pub mod video;
46
47#[cfg(feature = "opencv")]
48pub mod drawing;
49
50// Python bindings (requires "python" feature)
51#[cfg(feature = "python")]
52pub mod python;
53
54// Re-exports for convenience
55pub use camera_motion::CoordinateTransformation;
56pub use detection::Detection;
57pub use distances::{distance_by_name, Distance};
58pub use filter::{Filter, FilterFactory};
59pub use tracked_object::{TrackedObject, TrackedObjectFactory};
60pub use tracker::{Tracker, TrackerConfig};
61
62// Error types
63pub use crate::error::{Error, Result};
64
65mod error {
66    use thiserror::Error;
67
68    /// Errors that can occur in the norfair library
69    #[derive(Error, Debug)]
70    pub enum Error {
71        #[error("Invalid configuration: {0}")]
72        InvalidConfig(String),
73
74        #[error("Invalid detection: {0}")]
75        InvalidDetection(String),
76
77        #[error("Invalid points shape: expected {expected}, got {got}")]
78        InvalidPointsShape { expected: String, got: String },
79
80        #[error("Distance function error: {0}")]
81        DistanceError(String),
82
83        #[error("Filter error: {0}")]
84        FilterError(String),
85
86        #[error("Unknown distance function: {0}")]
87        UnknownDistance(String),
88
89        #[error("Coordinate transformation error: {0}")]
90        TransformError(String),
91
92        #[error("Metrics evaluation error: {0}")]
93        MetricsError(String),
94
95        #[error("IO error: {0}")]
96        IoError(#[from] std::io::Error),
97    }
98
99    /// Result type for norfair operations
100    pub type Result<T> = std::result::Result<T, Error>;
101}