fix: compare_host_align refuses pyrealsense2 without software depth units
Tried on pyrealsense2 2.50 (PC2's version): software_video_frame has no depth_units there, the software depth frames get scale 0 and rs.align returns an almost empty depth (1 valid pixel instead of 306565) with NO error. The read-only depth_units option on the sensor is not enough. The script now checks for the attribute and stops with an explicit message; 2.58 (this PC) works. rs.__version__ does not exist in 2.50 either: read with getattr. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
d345b733a2
commit
11e5bf5af5
1 file changed
+15
-3
@@ -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
|
||||
|
||||
|
||||
Reference in new issue
Block a user