# geekgineer/motcpp architecture

> Architecture diagram of the GitHub repository geekgineer/motcpp, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2026-08-27). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/geekgineer/motcpp
- Repository: https://github.com/geekgineer/motcpp

## Overview

#### 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: [`src/trackers/bytetrack.cpp`](https://github.com/geekgineer/motcpp/blob/main/src/trackers/bytetrack.cpp) (Tracker algorithms), [`include/motcpp/motcpp.hpp`](https://github.com/geekgineer/motcpp/blob/main/include/motcpp/motcpp.hpp) (Library API), [`src/motion/kalman_filter.cpp`](https://github.com/geekgineer/motcpp/blob/main/src/motion/kalman_filter.cpp) (Kalman motion), [`tools/motcpp_eval.cpp`](https://github.com/geekgineer/motcpp/blob/main/tools/motcpp_eval.cpp) (MOT evaluation CLI)

## Diagram (Mermaid)

```mermaid
flowchart TD

subgraph group_public["Public API"]
  node_public_api["Library API<br/>C++ headers<br/>[motcpp.hpp]"]
  node_tracker_base["Tracker lifecycle<br/>base tracker<br/>[tracker.hpp]"]
  node_example["Simple tracking example<br/>example executable"]
end

subgraph group_core["Tracking Core"]
  node_tracker_impl["Tracker algorithms<br/>concrete trackers<br/>[bytetrack.cpp]"]
  node_tracker_presets["Tracker presets<br/>YAML config<br/>[bytetrack.yaml]"]
  node_config["Configuration loader<br/>config parsing<br/>[config.cpp]"]
  node_motion["Kalman motion<br/>motion abstraction<br/>[kalman_filter.cpp]"]
  node_xyah_filter["XYAH filter<br/>Kalman model<br/>[xyah_kf.cpp]"]
  node_xysr_filter["XYSR filter<br/>Kalman model<br/>[xysr_kf.cpp]"]
  node_association["Cost &amp; matching<br/>association<br/>[matching.cpp]"]
  node_lap_solver["Linear assignment<br/>assignment solver<br/>[lap_solver.hpp]"]
end

subgraph group_extensions["Optional Cues"]
  node_reid["ReID backend<br/>appearance interface<br/>[reid_backend.cpp]"]
  node_onnx["ONNX inference<br/>optional backend<br/>[onnx_backend.cpp]"]
  node_cmc["Camera motion compensation<br/>optional motion cue<br/>[cmc.hpp]"]
end

subgraph group_evaluation["Evaluation Pipeline"]
  node_mot_dataset["MOT17 dataset loader<br/>data loader<br/>[mot17_dataset.cpp]"]
  node_eval_cli["MOT evaluation CLI<br/>CLI executable<br/>[motcpp_eval.cpp]"]
  node_mot_output["MOT output format<br/>output utility<br/>[mot_format.hpp]"]
  node_benchmark_script["Benchmark scoring<br/>Python script<br/>[eval_mot.py]"]
end

node_cmake["CMake build &amp; package<br/>[CMakeLists.txt]"]

node_cmake -->|"builds"| node_public_api
node_cmake -.->|"optionally enables"| node_onnx
node_public_api -->|"exposes"| node_tracker_base
node_example -->|"uses"| node_public_api
node_eval_cli -->|"instantiates"| node_public_api
node_tracker_presets -->|"parameters"| node_config
node_config -->|"configures"| node_tracker_impl
node_tracker_base -->|"shared lifecycle"| node_tracker_impl
node_tracker_impl -->|"predicts tracks"| node_motion
node_motion -->|"selects"| node_xyah_filter
node_motion -->|"selects"| node_xysr_filter
node_tracker_impl -->|"matches detections"| node_association
node_association -->|"solves assignments"| node_lap_solver
node_tracker_impl -.->|"optional appearance cue"| node_reid
node_reid -.->|"runs embeddings"| node_onnx
node_tracker_impl -.->|"optional camera cue"| node_cmc
node_mot_dataset -->|"sequences &amp; detections"| node_eval_cli
node_eval_cli -->|"writes tracks"| node_mot_output
node_mot_output -->|"scores"| node_benchmark_script

click node_cmake "https://github.com/geekgineer/motcpp/blob/main/CMakeLists.txt"
click node_public_api "https://github.com/geekgineer/motcpp/blob/main/include/motcpp/motcpp.hpp"
click node_tracker_base "https://github.com/geekgineer/motcpp/blob/main/include/motcpp/tracker.hpp"
click node_tracker_impl "https://github.com/geekgineer/motcpp/blob/main/src/trackers/bytetrack.cpp"
click node_tracker_presets "https://github.com/geekgineer/motcpp/blob/main/configs/trackers/bytetrack.yaml"
click node_config "https://github.com/geekgineer/motcpp/blob/main/src/config.cpp"
click node_motion "https://github.com/geekgineer/motcpp/blob/main/src/motion/kalman_filter.cpp"
click node_xyah_filter "https://github.com/geekgineer/motcpp/blob/main/src/motion/kalman_filters/xyah_kf.cpp"
click node_xysr_filter "https://github.com/geekgineer/motcpp/blob/main/src/motion/kalman_filters/xysr_kf.cpp"
click node_association "https://github.com/geekgineer/motcpp/blob/main/src/utils/matching.cpp"
click node_lap_solver "https://github.com/geekgineer/motcpp/blob/main/include/motcpp/association/lap_solver.hpp"
click node_reid "https://github.com/geekgineer/motcpp/blob/main/src/appearance/reid_backend.cpp"
click node_onnx "https://github.com/geekgineer/motcpp/blob/main/src/appearance/onnx_backend.cpp"
click node_cmc "https://github.com/geekgineer/motcpp/blob/main/include/motcpp/motion/cmc/cmc.hpp"
click node_example "https://github.com/geekgineer/motcpp/blob/main/examples/simple_tracking.cpp"
click node_mot_dataset "https://github.com/geekgineer/motcpp/blob/main/src/data/mot17_dataset.cpp"
click node_eval_cli "https://github.com/geekgineer/motcpp/blob/main/tools/motcpp_eval.cpp"
click node_mot_output "https://github.com/geekgineer/motcpp/blob/main/include/motcpp/utils/mot_format.hpp"
click node_benchmark_script "https://github.com/geekgineer/motcpp/blob/main/scripts/eval_mot.py"

classDef toneNeutral fill:#f8fafc,stroke:#334155,stroke-width:1.5px,color:#0f172a
classDef toneBlue fill:#dbeafe,stroke:#2563eb,stroke-width:1.5px,color:#172554
classDef toneAmber fill:#fef3c7,stroke:#d97706,stroke-width:1.5px,color:#78350f
classDef toneMint fill:#dcfce7,stroke:#16a34a,stroke-width:1.5px,color:#14532d
classDef toneRose fill:#ffe4e6,stroke:#e11d48,stroke-width:1.5px,color:#881337
classDef toneIndigo fill:#e0e7ff,stroke:#4f46e5,stroke-width:1.5px,color:#312e81
classDef toneTeal fill:#ccfbf1,stroke:#0f766e,stroke-width:1.5px,color:#134e4a
class node_public_api,node_tracker_base,node_example toneBlue
class node_tracker_impl,node_tracker_presets,node_config,node_motion,node_xyah_filter,node_xysr_filter,node_association,node_lap_solver toneAmber
class node_reid,node_onnx,node_cmc toneMint
class node_mot_dataset,node_eval_cli,node_mot_output,node_benchmark_script toneRose
class node_cmake toneNeutral
```

## Components

### Public API

- [Library API](https://github.com/geekgineer/motcpp/blob/main/include/motcpp/motcpp.hpp): C++ headers · Unified tracker API and public aggregation. · `include/motcpp/motcpp.hpp`
- [Tracker lifecycle](https://github.com/geekgineer/motcpp/blob/main/include/motcpp/tracker.hpp): base tracker · Owns prediction, association, track updates, filtering, and reset. · `include/motcpp/tracker.hpp`
- [Simple tracking example](https://github.com/geekgineer/motcpp/blob/main/examples/simple_tracking.cpp): example executable · `examples/simple_tracking.cpp`

### Tracking Core

- [Tracker algorithms](https://github.com/geekgineer/motcpp/blob/main/src/trackers/bytetrack.cpp): concrete trackers · Ten implementations select matching policies and enabled cues. · `src/trackers/bytetrack.cpp`
- [Tracker presets](https://github.com/geekgineer/motcpp/blob/main/configs/trackers/bytetrack.yaml): YAML config · `configs/trackers/bytetrack.yaml`
- [Configuration loader](https://github.com/geekgineer/motcpp/blob/main/src/config.cpp): config parsing · `src/config.cpp`
- [Kalman motion](https://github.com/geekgineer/motcpp/blob/main/src/motion/kalman_filter.cpp): motion abstraction · Trackers choose XYAH, XYSR, or XYWH box-state models. · `src/motion/kalman_filter.cpp`
- [XYAH filter](https://github.com/geekgineer/motcpp/blob/main/src/motion/kalman_filters/xyah_kf.cpp): Kalman model · `src/motion/kalman_filters/xyah_kf.cpp`
- [XYSR filter](https://github.com/geekgineer/motcpp/blob/main/src/motion/kalman_filters/xysr_kf.cpp): Kalman model · `src/motion/kalman_filters/xysr_kf.cpp`
- [Cost & matching](https://github.com/geekgineer/motcpp/blob/main/src/utils/matching.cpp): association · Builds IoU, appearance, and specialized costs before assignment. · `src/utils/matching.cpp`
- [Linear assignment](https://github.com/geekgineer/motcpp/blob/main/include/motcpp/association/lap_solver.hpp): assignment solver · `include/motcpp/association/lap_solver.hpp`

### Optional Cues

- [ReID backend](https://github.com/geekgineer/motcpp/blob/main/src/appearance/reid_backend.cpp): appearance interface · Crops frame detections and produces embeddings for appearance matching. · `src/appearance/reid_backend.cpp`
- [ONNX inference](https://github.com/geekgineer/motcpp/blob/main/src/appearance/onnx_backend.cpp): optional backend · `src/appearance/onnx_backend.cpp`
- [Camera motion compensation](https://github.com/geekgineer/motcpp/blob/main/include/motcpp/motion/cmc/cmc.hpp): optional motion cue · ECC or sparse optical flow provides pre-association compensation. · `include/motcpp/motion/cmc/cmc.hpp`

### Evaluation Pipeline

- [MOT17 dataset loader](https://github.com/geekgineer/motcpp/blob/main/src/data/mot17_dataset.cpp): data loader · Loads MOT-style sequence images and detections. · `src/data/mot17_dataset.cpp`
- [MOT evaluation CLI](https://github.com/geekgineer/motcpp/blob/main/tools/motcpp_eval.cpp): CLI executable · `tools/motcpp_eval.cpp`
- [MOT output format](https://github.com/geekgineer/motcpp/blob/main/include/motcpp/utils/mot_format.hpp): output utility · `include/motcpp/utils/mot_format.hpp`
- [Benchmark scoring](https://github.com/geekgineer/motcpp/blob/main/scripts/eval_mot.py): Python script · `scripts/eval_mot.py`

### Other components

- [CMake build & package](https://github.com/geekgineer/motcpp/blob/main/CMakeLists.txt): build · Builds the installable library and optional tools and ONNX support. · `CMakeLists.txt`

## Connections

- 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
