"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>
93 lines
2.7 KiB
Python
93 lines
2.7 KiB
Python
"""Parity tests for tracker/calibration.py against core/calibration.h's
|
|
behavior, mirroring tests/test_calibration.cpp's derive_arm_gains and
|
|
save_config/load_config cases so the two implementations are provably the
|
|
same function, not just similarly-named ones."""
|
|
|
|
import os
|
|
import sys
|
|
|
|
import pytest
|
|
|
|
ROOT = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
|
sys.path.insert(0, ROOT)
|
|
|
|
from tracker.calibration import ( # noqa: E402
|
|
ARM_GAIN_MAX,
|
|
ARM_GAIN_MIN,
|
|
TARGET_ARM_REACH_X,
|
|
TARGET_ARM_REACH_Y,
|
|
CalibrationConfig,
|
|
calibration_config_path,
|
|
derive_arm_gains,
|
|
load_config,
|
|
save_config,
|
|
)
|
|
|
|
|
|
def test_derive_arm_gains_averages_hold_and_scales_to_target_reach():
|
|
hold = [(0.5, 0.3)] * 16
|
|
gains, error = derive_arm_gains(hold)
|
|
assert error == ""
|
|
assert gains.x == pytest.approx(TARGET_ARM_REACH_X / 0.5, abs=1e-5)
|
|
assert gains.y == pytest.approx(TARGET_ARM_REACH_Y / 0.3, abs=1e-5)
|
|
|
|
|
|
def test_derive_arm_gains_succeeds_on_diagonal_up_and_out_gesture():
|
|
diagonal_hold = [(0.5, 0.3)] * 16
|
|
gains, error = derive_arm_gains(diagonal_hold)
|
|
assert error == ""
|
|
assert ARM_GAIN_MIN < gains.x < ARM_GAIN_MAX
|
|
assert ARM_GAIN_MIN < gains.y < ARM_GAIN_MAX
|
|
|
|
horizontal_hold = [(0.5, 0.0)] * 16
|
|
gains2, error2 = derive_arm_gains(horizontal_hold)
|
|
assert gains2 is None
|
|
assert "too small" in error2
|
|
|
|
|
|
def test_derive_arm_gains_clamps_to_range_and_rejects_bad_holds():
|
|
gains, error = derive_arm_gains([])
|
|
assert gains is None
|
|
assert error != ""
|
|
|
|
gains2, error2 = derive_arm_gains([(0.0, 0.0)])
|
|
assert gains2 is None
|
|
|
|
gains3, error3 = derive_arm_gains([(2.0, 2.0)])
|
|
assert gains3.x == pytest.approx(ARM_GAIN_MIN)
|
|
assert gains3.y == pytest.approx(ARM_GAIN_MIN)
|
|
|
|
|
|
def test_saved_config_reloads_with_identical_values():
|
|
original = CalibrationConfig(
|
|
depth_width=640,
|
|
depth_height=480,
|
|
z0_meters=2.6,
|
|
depth_gain=1.0,
|
|
mirror=True,
|
|
player_scale=1.23,
|
|
smoothing=(0.6, 0.4, 0.4, 0.04, 0.07),
|
|
floor_plane=(0.0, 1.0, 0.0, -0.9),
|
|
arm_gain_x=3.7,
|
|
arm_gain_y=3.0,
|
|
)
|
|
path = "/tmp/kinect_calibration_py_test.cfg"
|
|
try:
|
|
save_config(original, path)
|
|
loaded = load_config(path)
|
|
assert loaded == original
|
|
finally:
|
|
if os.path.exists(path):
|
|
os.remove(path)
|
|
|
|
|
|
def test_load_config_missing_file_returns_none():
|
|
assert load_config("/tmp/kinect_calibration_py_test_missing.cfg") is None
|
|
|
|
|
|
def test_calibration_config_path_honors_env_override():
|
|
assert calibration_config_path("/custom/path.cfg") == "/custom/path.cfg"
|
|
assert calibration_config_path(None).endswith(
|
|
os.path.join("VirtualKinect", "calibration.cfg")
|
|
)
|