The capture-thread decoupling (b513519) fixed inference backing up the
queue, but V4L2 webcams commonly buffer 4-5 frames internally in the driver
by default regardless of how fast userspace reads - a second, independent
latency source. Even a tight read() loop can return an already-stale
buffered frame. Set CAP_PROP_BUFFERSIZE=1 so every read() returns the
camera actual latest frame. No tracker-native equivalent exists (Media
Foundation IMFSourceReader is pull-based, no driver ring buffer to drain) -
this is a genuine Linux/V4L2-specific fix, not a port. 98/98 tests passing.
Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
Latency bug: Tracker._inference_worker read the camera and ran pose
inference in the same synchronous loop, so a slow model frame backs up the
camera driver queue and lag grows without bound - the same bug win_main.cpp
fixed natively (dedicated capture thread, condition-variable wake, latest-
frame-wins, no fixed poll).
Added _capture_worker on its own thread, storing only the latest frame
behind a lock+condvar; _inference_worker now waits for and consumes the
newest capture, never a queued one. run()/stop() start and join both
threads. Updated the regression test to drive capture then inference
synchronously (both are plain methods, no real threading needed for a
deterministic single-frame test). Full suite: 98/98 passing.
Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
"the cursor scaling is still wrong, make it like the windows one" - the
Linux tracker had no way to calibrate at all. The in-game cursor's arm-reach
gains (default 3.2/2.6) were tuned specifically for the native Windows
tracker's camera/pose characteristics via its "Calibrate cursor" button
(core/calibration.h's derive_arm_gains); Linux users were stuck on that
default regardless of their own camera/body, with no equivalent tool.
tracker/calibration.py is a byte-for-byte port of core/calibration.h's
arm-gain derivation (mean(|reach|) -> target/mean, clamped [1,6]) and the
calibration.cfg text format load_config()/save_config() share, so a config
written by either side is read identically by the shim - not a
reimplementation that happens to produce similar numbers, the same formula
and the same wire format, verified against tests/test_calibration.cpp's own
cases (averaging, diagonal-gesture success, horizontal-only rejection,
clamp-to-min, save/reload round-trip) ported 1:1 into
tests/test_calibration_py.py - 6/6 passing, plus the existing tracker suite
still 11/11.
tracker.py gets a --calibrate mode (calibrate_cursor()): mirrors each frame
for pose inference exactly like the main loop, computes Kinect joints with
mirror=False, and reads HAND_LEFT (index 7) minus SHOULDER_LEFT (index 4) -
the slots the player's actual right arm lands in post-mirror, pre-shim-swap,
matching exactly where win_main.cpp's CalibrateCursor() reads
skeleton.joints[7]/[4] (verified by reading that function directly). Usage:
nix run .#tracker -- --calibrate --source 0.
docs/calibration.md and docs/linux-wine.md document the Linux flow, the
Linux default config path (no %LOCALAPPDATA% equivalent - XDG config dir),
and that KINECT_SHIM_CONFIG must be set explicitly in both the calibration
tool's environment and the game's launch options (Wine or Proton) so they
agree on one file - the same pattern already established for
KINECT_SHIM_SHM_FILE.
Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
After the pose-mirror fix (5157651) made skeleton/depth correct, the RGB
video still looked wrong: mirrored on Linux where the user's actual Windows
reference showed a natural selfie-mirror video in-game. Checking the current
win_main.cpp + win_camera.cpp source shows no mirroring anywhere in the
publish path today - but that's inconsistent with what the user actually
observed on their working Windows setup, most likely because the deployed
exe predates a later "un-mirror for cursor accuracy" commit in this
project's history, or an earlier point in that mirror saga is what they
actually tested.
The published color buffer is fully independent of skeleton/cursor
correctness (driven only by the separate pose-inference path, verified
correct), so mirroring it carries no correctness risk. Tracker._inference_worker
now stores the same mirrored copy used for pose inference as self._latest_frame
(previously the raw capture), so the published color stream matches the
selfie-mirror video the user's Windows setup actually showed them.
Renamed/updated the regression test (now
test_inference_worker_mirrors_frame_for_pose_and_publish) to assert both the
pose-inference input and the published frame equal the mirrored copy. Full
suite: 11/11 passing.
Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
The in-game skeleton/cursor tracking was left/right reversed. Root cause:
tracker-native's win_main.cpp physically mirrors the captured frame
(pixel-level horizontal flip) before pose inference, but publishes the raw
unmirrored frame as the color stream, and runs its mapper with
cal_mapping_cfg.mirror=false (verified by reading win_main.cpp and
core/mapping.cpp directly). The shim's unconditional L/R joint swap
(fallback/windows-nui/src/sensor.cpp) then corrects MediaPipe's resulting
left/right mislabeling.
The Python tracker never physically mirrored the capture - it only applied a
coordinate-level flip (1-u) in joint_mapping.py, with FrameContractPublisher
defaulting mirror=True. That left joint identity already correct on its own
(no image mirror -> no MediaPipe mislabeling -> no swap needed), so the
shim's unconditional swap then flipped it backwards: the exact "tracking is
backwards" symptom.
Fix: Tracker._inference_worker now mirrors the frame (cv2.flip) before
handing it to the pose provider, exactly like win_main.cpp, while keeping
the raw frame for self._latest_frame (the published color stream).
FrameContractPublisher's mirror default changes to False to match
cal_mapping_cfg.mirror=false, so the physical flip isn't double-applied.
New regression test calls the real Tracker._inference_worker directly (not
a reimplementation) with an asymmetric synthetic frame and asserts the pose
provider receives the mirrored version while the stored/published frame
stays unmirrored. Updated test_publish_and_read_back_fake_pose to compute
its independent expectation with the publisher's actual mirror setting
instead of assuming it matches joint_mapping's own default. Full suite:
11/11 passing.
Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>
The Linux Python tracker is headless by design - no window, no camera
picker, no live preview; those only exist in the Windows-only
tracker-native/ GUI, which cannot run under Wine (docs/linux-wine.md). But
it also produced zero console output during a normal run, so a working
tracker and a silently stuck one looked identical - which is what prompted
"i don't see the window or picker or preview".
Added:
- a startup banner (camera source opening/opened, model loading, shm
target + resolution + fps) so a terminal run shows the pipeline actually
came up,
- a periodic "[tracker] frame=N fps=F player=tracked|lost seq=S" status
line (every 2s by default, Tracker.run(status_interval=...), disableable
for tests) so a long-running session shows live confirmation it is still
publishing frames and whether a person is currently detected.
Verified for real: ran the CLI against both a synthetic test video (confirms
the startup banner, mediapipe loads and infers) and a paced fake source
spanning several seconds (confirms the periodic status line fires on
schedule with the right frame/fps/player fields). Full tests/test_tracker.py
suite still passes (10/10, 0.78s) - the fast unit-test runs finish well
under the 2s default interval, so no new output or timing coupling there.
Co-authored-by: sisyphus-dev-ai <sisyphus-dev-ai@users.noreply.github.com>