docs(tracker-native): architecture for the zero-Python native tracker
ci / Linux C++ core (cmake + ctest) (push) Canceled after 0s
ci / Python root tests (pytest, no tracker deps) (push) Canceled after 0s
ci / Python tracker (pytest, tracker/.venv) (push) Canceled after 0s

Single native kinect-tracker.exe: Media Foundation camera enum/capture,
Dear ImGui (Win32+D3D11) device/resolution picker + live preview, pose +
segmentation via ONNX Runtime using the real MediaPipe BlazePose weights
converted from the .task TFLite bundle, native shm writer reusing the
existing C++ core (contract/mapping/synth). No Python, no committed binaries.
This commit is contained in:
kinect-bot committed 2026-11-25 18:23:06 -05:00
1 parent 00f64ab129
commit 290283d8c0
2 files changed
+103

No files matched your search

+97
View File
@@ -0,0 +1,97 @@
# Native tracker (zero-Python) — architecture
Status: in progress. Replaces the Python/MediaPipe tracker (`tracker/`) with a
single native Windows application. Goal from the user: pick the camera, pick the
resolution, see a live preview, and no Python anywhere.
## Why / scope
The Python tracker works but is a blind CLI (`--source 0 --depth-size 640x480`)
and drags a MediaPipe/OpenCV venv behind it. The new tracker is one native
`kinect-tracker.exe` that:
- enumerates webcams and their native resolutions, lets you pick both in a GUI,
- shows a live preview with a mask/skeleton overlay so you can frame yourself,
- runs pose + person segmentation natively,
- publishes the frozen IPC contract into the `kinect_virtual_frames` shared
memory the `Kinect10.dll` shim already reads.
## What is reused (already C++)
`core/` is the whole non-ML spine and already builds in the shim:
- `core/contract` — the exact shared-memory layout (seqlock triple buffer,
`#pragma pack(1)`, golden offsets). The native writer mirrors the Python
`FrameContractPublisher` using these structs directly.
- `core/mapping` — MediaPipe-33 landmarks → Kinect-20 joints.
- `core/synth` — synthetic depth from the segmentation mask + placed joints,
plus the mask stabilizer.
So the native tracker only adds: camera capture, inference, GUI, and the shm
*writer* (the shim already has the *reader*).
## Inference: faithful MediaPipe weights via ONNX Runtime
The `pose_landmarker_full.task` bundle is a zip of the real BlazePose GHUM
TFLite models:
- `pose_detector.tflite` — SSD-style person/pose detector (→ ROI).
- `pose_landmarks_detector.tflite` — 256×256 ROI → 33 landmarks (image + world)
+ visibility/presence + a 256×256 segmentation mask.
We convert both TFLite models to ONNX (tf2onnx) and run them with ONNX Runtime
(prebuilt Windows DLL, C++ API). This keeps the *exact* MediaPipe weights —
maximal fidelity — and only the pre/post-processing is reimplemented in C++:
1. letterbox the frame to the detector input, decode SSD anchors + NMS → pose ROI,
2. rotate/crop the ROI to 256×256 for the landmark model,
3. decode 33 landmarks back to image space; keep world landmarks + visibility,
4. take the segmentation mask head, un-rotate/un-crop back to frame space.
Each stage is validated headless on Linux against the Python MediaPipe output on
the same image (numpy A/B) before and after the C++ port, so correctness is
proven without the Windows GUI in the loop. The landmark output feeds
`core/mapping`; the mask feeds `core/synth` — unchanged.
## Capture: Media Foundation
Windows Media Foundation (MinGW-w64 headers available):
- `MFEnumDeviceSources(VIDCAP)` → device friendly names for the picker,
- `IMFSourceReader` → capture; `GetNativeMediaType` enumerates native
resolutions for the resolution picker,
- convert NV12/YUY2/RGB32 samples to BGR for inference + preview.
## GUI: Dear ImGui (Win32 + D3D11)
Standard ImGui `imgui_impl_win32` + `imgui_impl_dx11` backends (MinGW-buildable):
device dropdown, resolution dropdown, start/stop, live preview texture with an
optional mask/skeleton overlay, and a status line (published seq, fps, player
detected).
## Process / threading
Mirrors the Python design that already paces well:
- capture + inference on a worker thread caching the latest `(frame, pose, mask)`,
- a publish loop paced to a 30 fps monotonic deadline writing the shm contract,
- the GUI thread renders the preview from the latest cached frame.
## Build / target
- C++17, **64-bit** (`x86_64`). The shm layout is `pack(1)` fixed-offset, so a
64-bit writer and the 32-bit shim reader interoperate cleanly; 64-bit eases
ONNX Runtime + Media Foundation.
- CMake. Two toolchains: a Linux build of the inference core for headless
validation, and MinGW-w64 (or MSVC on the user's machine — Visual Studio is
installed) for the shipped `kinect-tracker.exe`.
- No committed binaries (standing agreement): models and the ONNX Runtime DLL
are fetched/generated by a setup step, not checked in.
## Shared-memory contract (must match the shim)
- Mapping name: `kinect_virtual_frames` (shim default; `KINECT_SHIM_SHM`
overrides on the shim side, `CreateFileMappingW` on ours).
- Layout: `nui::contract::FrameContract` + 3 `FrameSlot`s, then per-slot
depth (16-bit Kinect packed word) + color (BGRA), published via the seqlock in
`core/contract/contract.h`.
+6
View File
@@ -0,0 +1,6 @@
models/
*.tflite
*.onnx
*.exe
*.dll
build/