How geekgineer/motcpp works
Purpose and Entry Points
motcpp is a C++17 library for online multi-object tracking. Consumers link the CMake target and instantiate a concrete tracker; each accepts detector boxes plus an OpenCV frame through a unified update(dets, img) interface and returns tracked boxes/IDs. Public aggregation and base abstractions are in include/motcpp/motcpp.hpp, include/motcpp/tracker.hpp, and src/tracker.cpp. Runnable entry points are the usage example at examples/simple_tracking.cpp and MOT evaluation CLI at tools/motcpp_eval.cpp.
Build and Runtime Boundary
CMakeLists.txt builds an installable library, optionally examples, tests, tools, and ONNX support. Core runtime dependencies are Eigen (matrix data), OpenCV (frames and vision operations), and yaml-cpp (tracker configuration); ONNX Runtime is optional and acquired/integrated through cmake/DownloadONNXRuntime.cmake. The package export contract is cmake/motcppConfig.cmake.in.
Tracker Layer
Ten algorithm implementations share the base tracker lifecycle—state creation, prediction, association, update, output filtering, and reset—while differing in matching policy and enabled cues. Representative implementations are include/motcpp/trackers/bytetrack.hpp / src/trackers/bytetrack.cpp, include/motcpp/trackers/boosttrack.hpp / src/trackers/boosttrack.cpp, and src/trackers/ocsort.cpp. YAML presets provide externally selected tracker parameters in configs/trackers/bytetrack.yaml and configs/trackers/strongsort.yaml.
Per-Frame Tracking Flow
A caller supplies detections in [x1,y1,x2,y2,confidence,class] form and an image. The selected tracker predicts extant track state, partitions or filters detections as algorithm-specific, computes candidate costs, solves assignments, updates matched tracks, ages unmatched tracks, initializes eligible new tracks, and emits active tracks. Shared configuration parsing and tracker-facing settings are centralized in include/motcpp/config.hpp and src/config.cpp; MOT-format conversion/output utilities reside in include/motcpp/utils/mot_format.hpp.
Motion and Association Core
Kalman motion models represent box state in XYAH, XYSR, or XYWH forms; tracker implementations choose the appropriate model. The abstraction and base mechanics live in include/motcpp/motion/kalman_filter.hpp and src/motion/kalman_filter.cpp, with concrete filters in src/motion/kalman_filters/xyah_kf.cpp and src/motion/kalman_filters/xysr_kf.cpp. Association combines IoU, appearance, or specialized costs, then uses linear assignment through include/motcpp/association/lap_solver.hpp, src/utils/association.cpp, and src/utils/matching.cpp.
Appearance and Camera-Motion Extensions
ReID-capable trackers crop detections from the OpenCV frame, infer embeddings, and incorporate appearance distance into association. The backend boundary is include/motcpp/appearance/reid_backend.hpp, implemented by src/appearance/reid_backend.cpp; ONNX Runtime inference is isolated in include/motcpp/appearance/onnx_backend.hpp and src/appearance/onnx_backend.cpp. Moving-camera compensation is an optional pre-association signal behind include/motcpp/motion/cmc/cmc.hpp, with ECC and sparse optical-flow implementations in src/motion/cmc/ecc.cpp and src/motion/cmc/sof.cpp.
Data and Benchmark Pipeline
The library does not provide object detection; evaluation consumes MOT-style detections and sequence images. include/motcpp/data/mot17_dataset.hpp and src/data/mot17_dataset.cpp load MOT17 sequences, while tools/motcpp_eval.cpp runs tracker evaluation. Bundled mini data under assets/MOT17-mini/train/MOT17-02-FRCNN supports local validation; Python scripts such as scripts/eval_mot.py support benchmark scoring and release data workflows.
Main entry points: bytetrack.cpp Tracker algorithms · motcpp.hpp Library API · kalman_filter.cpp Kalman motion · motcpp_eval.cpp MOT evaluation CLI
Components 19
Public API
- Library API · Unified tracker API and public aggregation.
include/motcpp/motcpp.hpp - Tracker lifecycle · Owns prediction, association, track updates, filtering, and reset.
include/motcpp/tracker.hpp - Simple tracking example
examples/simple_tracking.cpp
Tracking Core
- Tracker algorithms · Ten implementations select matching policies and enabled cues.
src/trackers/bytetrack.cpp - Tracker presets
configs/trackers/bytetrack.yaml - Configuration loader
src/config.cpp - Kalman motion · Trackers choose XYAH, XYSR, or XYWH box-state models.
src/motion/kalman_filter.cpp - XYAH filter
src/motion/kalman_filters/xyah_kf.cpp - XYSR filter
src/motion/kalman_filters/xysr_kf.cpp - Cost & matching · Builds IoU, appearance, and specialized costs before assignment.
src/utils/matching.cpp - Linear assignment
include/motcpp/association/lap_solver.hpp
Optional Cues
- ReID backend · Crops frame detections and produces embeddings for appearance matching.
src/appearance/reid_backend.cpp - ONNX inference
src/appearance/onnx_backend.cpp - Camera motion compensation · ECC or sparse optical flow provides pre-association compensation.
include/motcpp/motion/cmc/cmc.hpp
Evaluation Pipeline
- MOT17 dataset loader · Loads MOT-style sequence images and detections.
src/data/mot17_dataset.cpp - MOT evaluation CLI
tools/motcpp_eval.cpp - MOT output format
include/motcpp/utils/mot_format.hpp - Benchmark scoring
scripts/eval_mot.py
Other components
- CMake build & package · Builds the installable library and optional tools and ONNX support.
CMakeLists.txt
Connections 19
- CMake build & package → Library API: builds
- CMake build & package → ONNX inference: optionally enables
- Library API → Tracker lifecycle: exposes
- Simple tracking example → Library API: uses
- MOT evaluation CLI → Library API: instantiates
- Tracker presets → Configuration loader: parameters
- Configuration loader → Tracker algorithms: configures
- Tracker lifecycle → Tracker algorithms: shared lifecycle
- Tracker algorithms → Kalman motion: predicts tracks
- Kalman motion → XYAH filter: selects
- Kalman motion → XYSR filter: selects
- Tracker algorithms → Cost & matching: matches detections
- Cost & matching → Linear assignment: solves assignments
- Tracker algorithms → ReID backend: optional appearance cue
- ReID backend → ONNX inference: runs embeddings
- Tracker algorithms → Camera motion compensation: optional camera cue
- MOT17 dataset loader → MOT evaluation CLI: sequences & detections
- MOT evaluation CLI → MOT output format: writes tracks
- MOT output format → Benchmark scoring: scores