Move Leap packed transforms into core
This commit is contained in:
parent
472515943b
commit
e90e15c520
4 changed files with 67 additions and 61 deletions
|
|
@ -54,6 +54,7 @@ from localcast.sensor_fusion.reservoir_window import (
|
|||
evidence_in_reservoir,
|
||||
render_points_in_reservoir,
|
||||
)
|
||||
from localcast.sensor_fusion.leap_packed import leap_channel_motion_points, unpack_leap_packed_channels
|
||||
from audio_field.cultcache_audio import frame_to_numpy, get_live_audio_phase_field, get_live_spatial_audio_frame
|
||||
|
||||
|
||||
|
|
@ -1057,65 +1058,6 @@ class LeapPackedMotionSampler:
|
|||
return frame
|
||||
|
||||
|
||||
def unpack_leap_packed_channels(frame_bgr: np.ndarray) -> dict[str, np.ndarray]:
|
||||
frame = frame_bgr.astype(np.float32) / 255.0
|
||||
blue = frame[:, :, 0]
|
||||
green = frame[:, :, 1]
|
||||
red = frame[:, :, 2]
|
||||
magenta = np.maximum(red, blue)
|
||||
return {
|
||||
"green": green,
|
||||
"magenta": magenta,
|
||||
"red": red,
|
||||
"blue": blue,
|
||||
}
|
||||
|
||||
|
||||
def leap_channel_motion_points(
|
||||
channel_name: str,
|
||||
current: np.ndarray,
|
||||
previous: np.ndarray,
|
||||
timestamp_ns: int,
|
||||
*,
|
||||
step: int,
|
||||
) -> list[RenderPointPacket]:
|
||||
height, width = current.shape[:2]
|
||||
motion = np.abs(current - previous)
|
||||
threshold = max(0.035, float(np.percentile(motion, 94)))
|
||||
points: list[RenderPointPacket] = []
|
||||
for row in range(0, height, step):
|
||||
for col in range(0, width, step):
|
||||
value = float(motion[row, col])
|
||||
intensity = float(current[row, col])
|
||||
if value < threshold and intensity < 0.10:
|
||||
continue
|
||||
u = col / max(1, width - 1)
|
||||
v = row / max(1, height - 1)
|
||||
x = -0.46 + 0.92 * u
|
||||
y = -0.16 + 0.68 * (1.0 - v)
|
||||
z = 0.74 + 0.58 * (1.0 - v) + 0.12 * intensity
|
||||
confidence = max(0.28, min(1.0, value * 3.8 + intensity * 0.42))
|
||||
if channel_name == "green":
|
||||
color = (0.28, 1.0, 0.62, 0.86)
|
||||
elif channel_name == "magenta":
|
||||
color = (1.0, 0.26, 0.92, 0.80)
|
||||
elif channel_name == "red":
|
||||
color = (1.0, 0.22, 0.18, 0.42)
|
||||
else:
|
||||
color = (0.20, 0.42, 1.0, 0.42)
|
||||
points.append(
|
||||
render_point(
|
||||
f"leap-motion:{channel_name}:{row}:{col}",
|
||||
np.array([x, y, z], dtype=np.float64),
|
||||
0.012 + 0.026 * confidence,
|
||||
color,
|
||||
confidence,
|
||||
timestamp_ns,
|
||||
)
|
||||
)
|
||||
return points
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser(description="Diagnostic replay of sensor-fusion render frames into typed CultCache state.")
|
||||
parser.add_argument("--cache", default=str(ROOT / "calibration" / "runs" / "visual-state.msgpack"))
|
||||
|
|
|
|||
64
localcast/sensor_fusion/leap_packed.py
Normal file
64
localcast/sensor_fusion/leap_packed.py
Normal file
|
|
@ -0,0 +1,64 @@
|
|||
"""Pure Leap packed-channel decoding and motion-point lowering."""
|
||||
|
||||
import numpy as np
|
||||
|
||||
from .render_bridge import RenderPointPacket
|
||||
|
||||
|
||||
def unpack_leap_packed_channels(frame_bgr: np.ndarray) -> dict[str, np.ndarray]:
|
||||
frame = frame_bgr.astype(np.float32) / 255.0
|
||||
blue = frame[:, :, 0]
|
||||
green = frame[:, :, 1]
|
||||
red = frame[:, :, 2]
|
||||
magenta = np.maximum(red, blue)
|
||||
return {
|
||||
"green": green,
|
||||
"magenta": magenta,
|
||||
"red": red,
|
||||
"blue": blue,
|
||||
}
|
||||
|
||||
|
||||
def leap_channel_motion_points(
|
||||
channel_name: str,
|
||||
current: np.ndarray,
|
||||
previous: np.ndarray,
|
||||
timestamp_ns: int,
|
||||
*,
|
||||
step: int,
|
||||
) -> list[RenderPointPacket]:
|
||||
height, width = current.shape[:2]
|
||||
motion = np.abs(current - previous)
|
||||
threshold = max(0.035, float(np.percentile(motion, 94)))
|
||||
points: list[RenderPointPacket] = []
|
||||
for row in range(0, height, step):
|
||||
for col in range(0, width, step):
|
||||
value = float(motion[row, col])
|
||||
intensity = float(current[row, col])
|
||||
if value < threshold and intensity < 0.10:
|
||||
continue
|
||||
u = col / max(1, width - 1)
|
||||
v = row / max(1, height - 1)
|
||||
x = -0.46 + 0.92 * u
|
||||
y = -0.16 + 0.68 * (1.0 - v)
|
||||
z = 0.74 + 0.58 * (1.0 - v) + 0.12 * intensity
|
||||
confidence = max(0.28, min(1.0, value * 3.8 + intensity * 0.42))
|
||||
if channel_name == "green":
|
||||
color = (0.28, 1.0, 0.62, 0.86)
|
||||
elif channel_name == "magenta":
|
||||
color = (1.0, 0.26, 0.92, 0.80)
|
||||
elif channel_name == "red":
|
||||
color = (1.0, 0.22, 0.18, 0.42)
|
||||
else:
|
||||
color = (0.20, 0.42, 1.0, 0.42)
|
||||
points.append(
|
||||
RenderPointPacket(
|
||||
stable_key=f"leap-motion:{channel_name}:{row}:{col}",
|
||||
xyz=np.array([x, y, z], dtype=np.float64),
|
||||
radius_m=0.012 + 0.026 * confidence,
|
||||
color_rgba=color,
|
||||
confidence=confidence,
|
||||
source_timestamp_ns=timestamp_ns,
|
||||
)
|
||||
)
|
||||
return points
|
||||
|
|
@ -75,3 +75,4 @@
|
|||
{"ts": "2026-05-19T10:03:37+00:00", "type": "implementation", "status": "ok", "note": "Native reservoir ABI now includes LocalcastAudioBlockDescriptor and localcast_producer_push_audio_block: audio producers pass caller-owned float32 interleaved block descriptors as payload handles while the reservoir keeps timing/retention ownership only."}
|
||||
{"ts": "2026-05-19T10:05:55+00:00", "type": "implementation", "status": "ok", "note": "Aquarium-Engine commit 34694e6 adds the C# LocalCast audio block descriptor binding and layout tests for the native LocalcastAudioBlockDescriptor/localcast_producer_push_audio_block ABI."}
|
||||
{"ts": "2026-05-19T10:07:55+00:00", "type": "implementation", "status": "ok", "note": "Reservoir-window clipping moved out of localcast.diagnostics.visual_producer into localcast.sensor_fusion.reservoir_window; audio overlay and tests now use the shared core invariant instead of importing diagnostic launcher code."}
|
||||
{"ts": "2026-05-19T10:09:53+00:00", "type": "implementation", "status": "ok", "note": "Leap packed-channel decoding and motion-point lowering moved from localcast.diagnostics.visual_producer into localcast.sensor_fusion.leap_packed; tests now import the pure core transform directly."}
|
||||
|
|
|
|||
|
|
@ -65,12 +65,11 @@ from localcast.diagnostics.render_math import (
|
|||
)
|
||||
from localcast.diagnostics.visual_producer import (
|
||||
LiveClapCalibrator,
|
||||
leap_channel_motion_points,
|
||||
rgb_dense_camera,
|
||||
rgb_dense_stereo_splats,
|
||||
rgb_room_splats,
|
||||
unpack_leap_packed_channels,
|
||||
)
|
||||
from localcast.sensor_fusion.leap_packed import leap_channel_motion_points, unpack_leap_packed_channels
|
||||
from localcast.sensor_fusion.reservoir_window import DEFAULT_RESERVOIR_NS, evidence_in_reservoir, render_points_in_reservoir
|
||||
from localcast.sensor_fusion.active_illumination import ActiveIlluminationController, IlluminationPulsePlan
|
||||
from audio_field.cultcache_audio import make_audio_source_events, make_spatial_audio_frame, put_live_spatial_audio_frame
|
||||
|
|
|
|||
Loading…
Reference in a new issue