Skip to main content

Fast object tracking library - Rust implementation of norfair

Project description

norfair-rs

Real-time multi-object tracking for Rust

License Rust Version


Disclaimer: This is an unofficial Rust port of Python's norfair object tracking library. This project is NOT affiliated with, endorsed by, or associated with Tryolabs or the original norfair development team. All credit for the original design and algorithms goes to the original norfair authors.


Overview

norfair-rs is a Rust implementation of the norfair multi-object tracking library, bringing real-time object tracking capabilities to Rust applications with:

  • Detector-agnostic design: Works with any object detector (YOLO, Faster R-CNN, custom models)
  • Rust-native performance: Zero-cost abstractions, no GC, maximum speed
  • Type-safe API: Compile-time validation of tracking configurations
  • Comprehensive Tests: 278 tests ensuring correctness and equivalence with the original norfair library

Related Projects

  • norfair - Original Python implementation by Tryolabs
  • norfair-go - Go port of norfair (sibling project)

Features

  • Flexible Distance Functions: IoU, Euclidean, Manhattan, Frobenius, Keypoint Voting, and more
  • Multiple Filtering Options: Optimized Kalman filter, full filterpy-equivalent Kalman, or no filtering
  • Camera Motion Compensation: Support for translation transformations (homography with opencv feature)
  • Re-identification: Optional feature embedding for robust identity matching
  • Thread-safe: Concurrent-safe ID generation and tracking

Benchmarks

Cross-language performance comparison (IoU distance, OptimizedKalmanFilter):

Scenario Frames Detections norfair norfair-go norfair-rs (python) norfair-rs (rust)
Small 100 446 4,700 fps 243,000 fps 107,000 fps 296,000 fps
Medium 500 9,015 540 fps 31,000 fps 27,000 fps 89,000 fps
Large 1,000 44,996 101 fps 3,800 fps 11,000 fps 41,000 fps
Stress 2,000 179,789 547 fps 5,200 fps 18,500 fps

Speedup norfair-rs (rust) vs norfair: 60-180x depending on scenario complexity Speedup norfair-rs (python) vs norfair: 20-50x (drop-in replacement)

Benchmarks run on Apple M3 Pro. See examples/benchmark/ for reproduction scripts.


Installation

Add to your Cargo.toml:

[dependencies]
norfair = { git = "https://github.com/nmichlo/norfair-rs" }

Quick Start

use norfair_rs::{Detection, Tracker, TrackerConfig};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    // 1. Create tracker with IoU distance function
    let mut config = TrackerConfig::from_distance_name("iou", 0.5);
    config.hit_counter_max = 30;
    config.initialization_delay = 3;

    let mut tracker = Tracker::new(config)?;

    // 2. For each frame
    for frame in iter_video_frames() {
        // 2.1 Generate detections from your object detector
        let detections: Vec<Detection> = detect_objects(&frame)
            .iter()
            .map(|bbox| {
                // Bounding box format: [x1, y1, x2, y2]
                Detection::from_slice(
                    &[bbox.x, bbox.y, bbox.x + bbox.w, bbox.y + bbox.h],
                    1, 4  // 1 row, 4 columns
                ).unwrap()
            })
            .collect();

        // 2.2 Update tracker, returning current tracked objects with stable IDs
        let tracked_objects = tracker.update(detections, 1, None);

        // 2.3 Use tracked objects (draw, analyze, etc.)
        for obj in tracked_objects {
            if let Some(id) = obj.id {
                draw_box(&frame, &obj.estimate, id);
            }
        }
    }

    Ok(())
}
Python Norfair Equivalent

Here's how the same tracking workflow looks in the original Python norfair library:

Python:

from norfair import Detection, Tracker

# Create tracker
tracker = Tracker(
    distance_function="iou",
    distance_threshold=0.5,
    hit_counter_max=30,
    initialization_delay=3,
)

# Process frames
for frame in iter_video_frames():
    # Get detections from your detector
    detections = [
        Detection(points=np.array([[x1, y1, x2, y2]]))
        for x1, y1, x2, y2 in detect_objects(frame)
    ]

    # Update tracker
    tracked_objects = tracker.update(detections=detections)

    # Use tracked objects
    for obj in tracked_objects:
        draw_box(frame, obj.estimate, obj.id)

Key Differences:

  • Rust: Explicit configuration structs vs Python kwargs
  • Rust: Error handling with Result<T, E> returns
  • Rust: Uses nalgebra matrices instead of numpy arrays
  • Rust: Zero-cost abstractions with compile-time guarantees

Both implementations provide the same core functionality with Rust offering better performance.

Configuration Options

use norfair_rs::{TrackerConfig, filter::OptimizedKalmanFilterFactory};
use norfair_rs::distances::distance_by_name;

let mut config = TrackerConfig::new(distance_by_name("euclidean"), 50.0);

// Tracking behavior
config.hit_counter_max = 15;           // Frames to keep tracking without detection
config.initialization_delay = 3;       // Detections required to initialize
config.pointwise_hit_counter_max = 4;  // Per-point tracking threshold
config.detection_threshold = 0.5;      // Minimum detection confidence
config.past_detections_length = 4;     // History for re-identification

// Re-identification (optional)
config.reid_distance_function = Some(distance_by_name("euclidean"));
config.reid_distance_threshold = 100.0;
config.reid_hit_counter_max = Some(50);

// Kalman filter
config.filter_factory = Box::new(OptimizedKalmanFilterFactory::new(
    4.0,   // R (measurement noise)
    0.1,   // Q (process noise)
    10.0,  // P (initial covariance)
    0.0,   // pos_variance
    1.0,   // vel_variance
));

Distance Functions

Built-in distance functions available via distance_by_name():

Name Description Use Case
"euclidean" L2 distance between points Single-point tracking
"iou" 1 - Intersection over Union Bounding box tracking
"mean_euclidean" Average L2 across all points Multi-keypoint tracking
"mean_manhattan" Average L1 across all points Grid-aligned tracking
"frobenius" Frobenius norm of difference Matrix comparison

Custom distance functions can be implemented via the Distance trait.

Filter Options

Three filter types are available:

use norfair_rs::filter::{
    OptimizedKalmanFilterFactory,  // Fast, simplified Kalman (default)
    FilterPyKalmanFilterFactory,    // Full filterpy-compatible Kalman
    NoFilterFactory,                // No prediction (detection-only)
};

API Documentation

Core Types

  • Tracker - Main tracking engine that maintains object identities across frames
  • Detection - Input from object detector (bounding boxes, keypoints, or arbitrary points)
  • TrackedObject - Output object with stable ID, position estimate, and tracking metadata
  • TrackerConfig - Configuration for tracker behavior
  • TrackedObjectFactory - Thread-safe ID generation

Camera Motion

use norfair_rs::camera_motion::TranslationTransformation;

// Compensate for camera movement
let transform = TranslationTransformation::new([dx, dy]);
let tracked = tracker.update(detections, 1, Some(&transform));

Feature Flags

[dependencies]
norfair = { git = "...", features = ["opencv"] }
Feature Description
opencv Enable video I/O, drawing, and homography transforms

License & Attribution

norfair-rs is licensed under the BSD 3-Clause License.

This Rust port is based on the original norfair by Tryolabs (BSD 3-Clause). Their well-designed, detector-agnostic architecture made this port possible. Internal modules include code adapted from several Python libraries—see THIRD_PARTY_LICENSES.md for complete attribution.

Citation: If using this library in research, please cite the original norfair paper as described here.


Contributing: Issues and pull requests welcome!

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

norfair_rs-0.1.0.tar.gz (1.2 MB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

norfair_rs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (391.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

norfair_rs-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (391.7 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

norfair_rs-0.1.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (392.3 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

norfair_rs-0.1.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (393.7 kB view details)

Uploaded PyPymanylinux: glibc 2.17+ ARM64

norfair_rs-0.1.0-cp312-abi3-win_amd64.whl (282.2 kB view details)

Uploaded CPython 3.12+Windows x86-64

norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (402.1 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ x86-64

norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (387.0 kB view details)

Uploaded CPython 3.12+manylinux: glibc 2.17+ ARM64

norfair_rs-0.1.0-cp312-abi3-macosx_11_0_arm64.whl (359.7 kB view details)

Uploaded CPython 3.12+macOS 11.0+ ARM64

norfair_rs-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl (382.2 kB view details)

Uploaded CPython 3.12+macOS 10.12+ x86-64

File details

Details for the file norfair_rs-0.1.0.tar.gz.

File metadata

  • Download URL: norfair_rs-0.1.0.tar.gz
  • Upload date:
  • Size: 1.2 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for norfair_rs-0.1.0.tar.gz
Algorithm Hash digest
SHA256 89c77e8e39bc37933a6911b2db0f69b835b8f3ed7f672673176a2b446b58cfd4
MD5 357f899ba3651eec00dda87ce947a95c
BLAKE2b-256 2f09522d5a56ce263ee0b32716cc84373ac36942e126dee0dac452ab7ebeef88

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0.tar.gz:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 70129e91bc5b1d44469e32c14e3b8578d5be4e5d43b5e3570c9c7812b65c8b98
MD5 543d27d658da6c9247807d7339d77182
BLAKE2b-256 420a6021a44b8ac4033a407eb4e96d82bffbc5808765604e82032ef917a60248

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 49add7e56d48a169244bf61daf6124f3da87d636ee77576805f413c766c3bfc0
MD5 9b50ed572488b40e0fe15395b1eafae4
BLAKE2b-256 eb4fe1603d06a30ced118bb797d9fe305a730452c6ba98da1fb564f79d789b3c

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7b4ee8e73d004c7e6a1f12f1a7929f71ef2b7cbe95b1d6c9b5fb37e95d33e28a
MD5 850e259e27c7124764ddc3cecefbde9f
BLAKE2b-256 166b97045e10ed4b3826cd8f24878770775894cadcf0df1b09ea4b7e359fb325

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 7d1c9ba2ce22be275924038a6f7b5b193b4fd1f70ff366b0239367337391bdf4
MD5 240e319ab7dbc0d694b7cd751aefda1a
BLAKE2b-256 d3889af2c0b0abc6208223e7ec604f1c19bb7d74b9ef2ec4c89d3acb49c5268b

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-pp37-pypy37_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-cp312-abi3-win_amd64.whl.

File metadata

  • Download URL: norfair_rs-0.1.0-cp312-abi3-win_amd64.whl
  • Upload date:
  • Size: 282.2 kB
  • Tags: CPython 3.12+, Windows x86-64
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for norfair_rs-0.1.0-cp312-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 582bf3affc2b69fd4eb2a6b43af8844a608e0a96a9c1794c4efa376d327edbc9
MD5 959cda67b6105969fefcddf146ae4e85
BLAKE2b-256 2594f701fc36eb6faa93cc973e1f5be50c8ec374c8af20c8d4679cb6dae50cc8

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-cp312-abi3-win_amd64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 64c1ce9f801f1ad9dee6718ffb977fae566b00a962280be32853ad16f195a2cb
MD5 1f6dfd95229a0fef9d4d48b621f290f7
BLAKE2b-256 36953b7c735555aa9690badf205424e3dfb4d7081a3970854aa0a73ac0c5f1c4

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 05c9a3f3c47f25740b802187e37914489374e800a76f2e995f32c9e736b5c48a
MD5 82633983d818c8c0c85c824fda2188a8
BLAKE2b-256 d290341f4f0e8bf1758073792660278a845f07ab2c3c6b90448fb4c54dbfcb0f

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-cp312-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-cp312-abi3-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-cp312-abi3-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 80d709fc54e78f82fa64da4bf50da4ba7a92526cc9ceac27fd091d61e30e3a7f
MD5 24c0d1f630d0a55e738227262f8f7dc2
BLAKE2b-256 99d6ac50a042271dd4f954a5ba4993c98e11ced986e0ef1164fc40ca9c7a641b

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-cp312-abi3-macosx_11_0_arm64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file norfair_rs-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl.

File metadata

File hashes

Hashes for norfair_rs-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl
Algorithm Hash digest
SHA256 b6d9606f73be2a5072c773af5000e7cafc6212e3bf44c07ddfeb2f30d96baa35
MD5 4ce68c63d2b3dee805fc100f4cbfeae7
BLAKE2b-256 75b556af64f482e9b02d1aa40615f0da901b0821367f64ee29bd87cd9f83c21b

See more details on using hashes here.

Provenance

The following attestation bundles were made for norfair_rs-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl:

Publisher: release.yml on nmichlo/norfair-rs

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page