diff --git a/scripts/compare_host_align.py b/scripts/compare_host_align.py index 873d2f9..8bf6017 100644 --- a/scripts/compare_host_align.py +++ b/scripts/compare_host_align.py @@ -10,7 +10,10 @@ pixel, how the two aligned depths differ. Prints one JSON line per frameset and a summary. Only GET requests; nothing on PC2 changes. The host's pyrealsense2 may be newer than PC2's (2.58 here, 2.50 there): the -two aligns are then not even the same code version. +two aligns are then not even the same code version. It must have +software_video_frame.depth_units: pyrealsense2 2.50 has not, and there the +software frames' depth scale is 0, so rs.align returns an (almost) empty +depth WITHOUT any error. The script refuses to run on such a version. """ import argparse @@ -51,10 +54,19 @@ def rs_extrinsics(ext: dict) -> rs.extrinsics: # Host align --------------------------------------------------------------------- +def require_software_depth_units() -> None: + """Raise unless this pyrealsense2 can give software depth frames their units (not 2.50).""" + if not hasattr(rs.software_video_frame(), "depth_units"): + raise RuntimeError( + f"pyrealsense2 {getattr(rs, '__version__', '(no __version__, e.g. 2.50)')} has no " + "software_video_frame.depth_units: the host align would come out empty. Use a newer one (2.58 works).") + + class HostAligner: """rs.align(color) on frames pushed into a software_device with PC2's calibration.""" def __init__(self, calibration: dict): + require_software_depth_units() self._device = rs.software_device() self._depth = self._device.add_sensor("Depth") self._color = self._device.add_sensor("Color") @@ -129,7 +141,7 @@ def _push(sensor, profile, pixels: np.ndarray, bpp: int, number: int, stamp_ms: frame.frame_number = number frame.profile = profile.as_video_stream_profile() if depth: - frame.depth_units = 0.001 + frame.depth_units = 0.001 # millimeters (checked to exist by require_software_depth_units) sensor.on_video_frame(frame) @@ -204,7 +216,7 @@ def main(argv=None) -> int: results.append(result) print(json.dumps(result)) means = [r["abs_diff_mm"]["mean"] for r in results if r["abs_diff_mm"]] - print(json.dumps({"summary": {"framesets": len(results), "pyrealsense2_host": rs.__version__, + print(json.dumps({"summary": {"framesets": len(results), "pyrealsense2_host": getattr(rs, "__version__", "unknown"), "mean_abs_diff_mm_per_frameset": means}})) return 0