How tryolabs/norfair works
1. What this repository is
- Norfair is a Python library for real-time multi-object tracking, not a standalone application.
- The architecture centers on a small tracking core that can be embedded into many different computer-vision pipelines.
2. Core package boundary
- The main runtime code lives under norfair/.
- This package is the product boundary: external code provides detections and optional video frames, and Norfair returns tracked objects with stable IDs over time.
- The public API is exposed from norfair/__init__.py.
3. Tracking pipeline
- The primary flow is: detector output → Detection objects → Tracker update → tracked objects.
- Detections are not limited to boxes; they are represented as one or more points, which is the key abstraction that makes Norfair detector-agnostic.
- The tracker performs frame-to-frame association and state prediction, then assigns or preserves track identities.
4. Association and motion model
- tracker.py, distances.py, and filter.py are the core tracking subsystems.
- distances.py defines how detections and tracked objects are compared; this is intentionally pluggable and is a major architectural seam.
- filter.py provides the prediction/smoothing layer used by the tracker, so association is based on estimated positions rather than raw last-frame positions.
5. Advanced tracking features
- camera_motion.py handles compensation for moving cameras, which changes the coordinate frame before matching.
- The library also supports higher-dimensional tracking and appearance-based re-identification, which are showcased in demos rather than being a separate top-level service.
- This means the tracker can operate in multiple modes depending on whether the input scene is static, camera-stabilized, or requires ReID.
6. Video and frame I/O utilities
- video.py contains helpers for reading and writing frame streams, likely built around OpenCV.
- This is a utility boundary: it helps create end-to-end inference loops, but it is not required for using the tracker itself.
- In architecture diagrams, this sits alongside the core tracker as an optional adapter to video sources and sinks.
7. Visualization layer
- norfair/drawing/ contains rendering utilities for tracked objects, boxes, points, paths, and fixed-camera / grid overlays.
- Drawing is separate from tracking logic, which keeps the tracker headless and reusable in non-visual pipelines.
- The demos use these helpers heavily to visualize track IDs and trajectories on video frames.
8. Metrics and evaluation
- metrics.py is a separate subsystem for evaluation, used for MOT-style benchmarking.
- The repo includes a demos/motmetrics4norfair area and tests around MOT outputs, indicating that evaluation is treated as an auxiliary workflow rather than core runtime logic.
- This supports architecture diagrams that distinguish production tracking from offline assessment.
9. Demos as integration examples
- The large demos/ tree is a collection of integration adapters for different detectors and scenarios: YOLO variants, Detectron2, AlphaPose, OpenPose, SAHI, YOLO-NAS, camera motion, 3D tracking, profiling, and ReID.
- Each demo is mostly a thin pipeline glue layer: detector-specific preprocessing/inference on one side, Norfair tracking in the middle, and optional drawing/output on the other.
- These demos show that Norfair is designed to slot into heterogeneous ML stacks rather than impose its own detector.
10. Documentation and developer tooling
- docs/ is a MkDocs-based documentation site, with generated reference pages for each major module.
- tests/ covers distances, drawing, tracker behavior, and metrics-related behavior, which maps closely to the core package boundaries.
- CI, linting, packaging, and release automation live in .github/workflows, pyproject.toml, tox.ini, and .pylintrc, indicating a conventional Python library lifecycle.
11. External dependencies and runtime shape
- OpenCV is a material dependency for video handling and drawing; GPU-centric detector frameworks appear only in demos.
- The core library itself is designed to be lightweight and detector-agnostic, so most heavy ML dependencies are intentionally pushed to demo-specific subprojects.
- This separation is important: the library stays small, while integrations carry the cost of any specific detector or pose model.
12. How to draw the architecture
- A good diagram would place Norfair core tracking in the center, with arrows in from “detector outputs” and “video/frame stream,” and arrows out to “tracked objects,” “visualization,” and “metrics/evaluation.”
- Around that core, show optional modules for camera motion, ReID, drawing, and video I/O.
- Outside the package boundary, show the many detector/demo integrations as interchangeable upstream producers of detections.
Main entry points: tracker.py Tracker · __init__.py Public API · camera_motion.py Camera motion · distances.py Distances
Components 15
Core library
Detector-agnostic tracking runtime and its main subsystems.
- Public API · Exports the library entry points for embedding Norfair in external pipelines.
norfair/__init__.py - Tracker · Maintains track state, performs frame-to-frame association, and assigns stable IDs.
norfair/tracker.py - Distances · Pluggable comparison logic between detections and tracked objects.
norfair/distances.py - Filter · Prediction and smoothing layer used before matching and identity assignment.
norfair/filter.py - Camera motion · Compensates for moving cameras by transforming the matching coordinate frame.
norfair/camera_motion.py - Video I/O · Helpers for reading and writing video frame streams around the tracker.
norfair/video.py - Metrics · MOT-style evaluation helpers for benchmarking tracker outputs.
norfair/metrics.py - Drawing · Rendering utilities for boxes, points, paths, grids, and fixed-camera overlays.
norfair/drawing/__init__.py
Demo integrations
Example pipelines that plug detectors, tracking, drawing, and evaluation together.
- Detector demos · YOLO, Detectron2, SAHI, MMDetection, YOLO-NAS, and related detector adapters.
demos/yolov5/src/demo.py - Pose / 3D demos · Keypoint, pose, and 3D tracking pipelines that feed point-based detections into Norfair.
demos/openpose/src/demo.py - ReID demo · Appearance-based re-identification workflow layered on top of tracking.
demos/reid/src/demo.py - Camera demo · End-to-end example for moving-camera scenes and stabilization.
demos/camera_motion/src/demo.py - MOT metrics demo · Offline benchmarking and comparison workflows for tracking outputs.
demos/motmetrics4norfair/src/motmetrics4norfair.py
Docs and tooling
Documentation site and repository maintenance workflow.
- Docs site · MkDocs-based project documentation and generated module references.
docs/reference/index.md - CI workflows · GitHub Actions, packaging, linting, and release automation.
.github/workflows/ci.yml
Connections 19
- Detector demos → Tracker: detections · Detector pipelines produce Norfair detections for association.
- Pose / 3D demos → Tracker: points · Pose and 3D examples feed point-based detections into the core tracker.
- ReID demo → Tracker: tracked IDs · ReID examples augment tracking with appearance-based identity recovery.
- Camera demo → Camera motion: stabilize · Camera-motion examples use motion compensation before matching.
- Camera motion → Tracker: compensated frame · Transforms coordinates before association runs.
- Video I/O → Tracker: frames · Optional frame streams provide image context for end-to-end loops.
- Distances → Tracker: match cost · Distance functions drive object-to-detection association.
- Filter → Tracker: prediction · State estimates are used to predict and smooth track positions.
- Tracker → Drawing: visualize · Tracked objects can be rendered as boxes, points, or paths.
- Tracker → Metrics: outputs · Tracker results are evaluated against MOT-style metrics.
- MOT metrics demo → Metrics: benchmark · Evaluation demo wraps the metrics subsystem.
- Public API → Tracker: exports · Public package surface exposes the core tracker entry points.
- Public API → Distances: exports · Distance abstractions are part of the public API.
- Public API → Filter: exports · Filter abstractions are available to consumers.
- Public API → Camera motion: exports · Camera motion helpers are exposed for advanced use cases.
- Public API → Video I/O: exports · Video helpers are exposed as optional utilities.
- Public API → Drawing: exports · Drawing helpers are available for visualization pipelines.
- Docs site → Public API: documents · Reference docs cover the main library modules and API.
- CI workflows → Docs site: builds · Automation validates, builds, and publishes documentation and releases.