# tracker/ — webcam pose + segmentation tracker (plan todo 5) Python pipeline: OpenCV capture (webcam **or** video file) → MediaPipe Pose Landmarker (33 normalized landmarks + 33 world landmarks in metres + per-landmark visibility + segmentation mask) → published to the frozen shared-memory IPC contract (`tracker/contract.py`, mirror of `core/contract/contract.h`) at the newest-wins slot each frame, plus a control-plane handshake/heartbeat. ## Layout | file | role | |------|------| | `pose.py` | `PoseResult`, `PoseProvider` seam, `MediaPipePoseProvider` (Tasks API, VIDEO mode) | | `publisher.py` | `FrameContractPublisher` — shared-memory triple-buffer producer (seqlock publish) | | `control.py` | handshake + heartbeat control plane over a unix socket | | `tracker.py` | capture + background inference + monotonic-clock publish loop + CLI | | `fake_pose.py` | synthetic providers/sources that drive the data path without MediaPipe | ## Design (satisfies the plan's MUST-NOTs) - **Inference never blocks the publish path.** Capture + inference run on a background thread and cache the latest `(frame, PoseResult)`; the publish loop publishes whatever is latest, re-publishing the previous pose when inference is slower than the cadence. - **No fixed sleeps.** The publish loop paces to a monotonic frame clock (`deadline = start + n·period`) and waits exactly until the next deadline. - **Scope boundary.** The 20 contract joints are a *provisional* pass-through of the raw MediaPipe world landmarks, and the depth buffer is a flat mask→silhouette placeholder. The real MediaPipe-33 → Kinect-20 mapping (todo 6) and the articulated synthetic-depth rasterizer (todo 7) replace these; todo 5 owns only moving a pose through the contract at a steady cadence. ## Environment setup (this host: Python 3.14, no sudo/apt-install) The system Python is 3.14, which has **no MediaPipe wheel**, and `python3-venv`'s `ensurepip` is missing. The working route is user-space [`uv`](https://github.com/astral-sh/uv): ```sh pip install --user --break-system-packages uv export PATH="$HOME/.local/bin:$PATH" uv python install 3.12 uv venv --python 3.12 tracker/.venv uv pip install --python tracker/.venv numpy pytest opencv-python-headless mediapipe ``` Installed here: Python 3.12.16, numpy 2.5.5, opencv-python-headless 5.1.0, mediapipe 1.2.3. ### MediaPipe model bundles mediapipe ≥ 1.x ships only the Tasks API (no legacy `mp.solutions.pose`); it loads a `.task` bundle. Download the tiers into `tracker/models/` (git-ignored): ```sh base="https://storage.googleapis.com/mediapipe-models/pose_landmarker" for t in lite full heavy; do curl -fsSL -o tracker/models/pose_landmarker_$t.task \ "$base/pose_landmarker_$t/float16/latest/pose_landmarker_$t.task" done ``` ### System GL library (user-space workaround) mediapipe 1.2.3's C bindings need `libGLESv2.so.2`, which is absent on this box and cannot be `apt install`ed without sudo. It was supplied user-space (no sudo) via: ```sh cd /tmp && apt-get download libgles2 && dpkg-deb -x libgles2_*.deb ext mkdir -p ~/.cache/kinect/gllibs && cp -a ext/usr/lib/*/libGLESv2.so.2* ~/.cache/kinect/gllibs/ export LD_LIBRARY_PATH="$HOME/.cache/kinect/gllibs:$LD_LIBRARY_PATH" ``` ## Run ```sh export LD_LIBRARY_PATH="$HOME/.cache/kinect/gllibs:$LD_LIBRARY_PATH" # webcam: tracker/.venv/bin/python -m tracker.tracker --source 0 --model full # recorded file: tracker/.venv/bin/python -m tracker.tracker --source clip.avi --model full --max-frames 300 # benchmark the tiers and exit: tracker/.venv/bin/python -m tracker.tracker --source clip.avi --measure-fps ``` ## Tests & measured evidence ```sh tracker/.venv/bin/python -m pytest tests/test_tracker.py -v ``` Data-path suite is green (9/9): fake-pose → contract packing → shared-memory publish → read-back, plus the no-person (low-visibility / no-body) frame and the control-plane handshake/heartbeat round-trip. Full repo Python suite: 73 passed. Live MediaPipe smoke (recorded 256×256 synthetic-humanoid clip, CPU/XNNPACK): real 33-landmark detection (x∈[0.21,0.79], y∈[0.21,0.93]), world landmarks in metres, a 256×256 segmentation mask, `tracking_id=1`, depth body pixels published, publish cadence ~31.6 fps. Measured inference fps on this CPU: | tier | fps (256×256, CPU) | |------|--------------------| | lite | ~80 | | full | ~62 | | heavy | ~20 | → **full** is the selected tier (comfortably ≥25 fps on CPU at this resolution; heavy drops below 25). Measured at 256×256; fps at 640×480 will be lower and should be re-measured against the real capture resolution. Evidence: `.omo/evidence/task-5-webcam-kinect-emulator.log`. ## Blocked / not verified here [~] - **Live webcam device**: this headless WSL2 box has no camera; the pipeline was validated against a recorded video file (as the plan prescribes for determinism). Running against `--source 0` on real hardware is unverified. - **GPU inference tier**: no GPU on this host; all fps numbers are CPU/XNNPACK. - **fps at 640×480**: measured at 256×480→256×256 only; re-measure at the host's requested capture/stream resolution before committing to the `full` tier. - **libGLESv2.so.2**: required a user-space deb-extraction workaround (above); a proper deploy should install the system `libgles2` package.