feat(viz): /pose/hands OSC sender

This commit is contained in:
L'électron rare
2026-06-26 09:37:13 +02:00
parent 71d0a47723
commit 7a4f14056a
2 changed files with 66 additions and 0 deletions
+18
View File
@@ -321,6 +321,24 @@ class PoseSoundBridge:
[int(pid), float(kin[0]), float(kin[1]), float(kin[2])],
)
@staticmethod
def _hand_slot(h):
if not h:
return [0.0, 0.0, 0.0, 0.0]
return [float(h["cx"]), float(h["cy"]),
float(h["openness"]), float(h["speed"])]
def send_hands(self, feats, t):
"""Emit /pose/hands [0, lx,ly,lopen,lspeed, rx,ry,ropen,rspeed, dist]."""
args = [0]
args += self._hand_slot(feats.get("L"))
args += self._hand_slot(feats.get("R"))
args.append(float(feats.get("dist", 0.0)))
try:
self._client.send_message("/pose/hands", args)
except OSError:
pass
def send_enter(self, pid: int) -> None:
"""Send lifecycle event when person enters frame."""
self._client.send_message("/pose/enter", [int(pid)])
@@ -0,0 +1,48 @@
from data_only_viz.pose_bridge import PoseSoundBridge
class FakeClient:
def __init__(self):
self.sent = []
def send_message(self, addr, args):
self.sent.append((addr, args))
def _bridge():
b = PoseSoundBridge.__new__(PoseSoundBridge) # bypass __init__/sockets
b._client = FakeClient()
return b
def test_send_hands_both_present():
b = _bridge()
feats = {
"L": {"cx": 0.2, "cy": 0.4, "openness": 0.9, "speed": 0.1},
"R": {"cx": 0.8, "cy": 0.3, "openness": 0.5, "speed": 0.0},
"dist": 0.6,
}
b.send_hands(feats, t=1.0)
addr, args = b._client.sent[-1]
assert addr == "/pose/hands"
assert args[0] == 0
assert args[1:5] == [0.2, 0.4, 0.9, 0.1]
assert args[5:9] == [0.8, 0.3, 0.5, 0.0]
assert args[9] == 0.6
assert len(args) == 10
def test_send_hands_left_only_zero_pads_right():
b = _bridge()
feats = {"L": {"cx": 0.5, "cy": 0.5, "openness": 0.7, "speed": 0.2},
"R": None, "dist": 0.0}
b.send_hands(feats, t=1.0)
_, args = b._client.sent[-1]
assert args[5:9] == [0.0, 0.0, 0.0, 0.0]
def test_send_hands_none_emits_all_zero():
b = _bridge()
b.send_hands({"L": None, "R": None, "dist": 0.0}, t=1.0)
_, args = b._client.sent[-1]
assert args == [0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0]