Skip to content

Commit b4e613d

Browse files
Updated emulated_rgbd's stream_gripper_rgbd to do the point cloud calculation on the NUC instead of the luxonis device to bring FPS back to 30
1 parent 9cc1daf commit b4e613d

1 file changed

Lines changed: 46 additions & 3 deletions

File tree

stretch4_body/subsystem/cameras/emulated_rgbd.py

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -519,16 +519,59 @@ def stream_left_right_center_rgbd(*, is_rotate=True, use_left_lidar=True, use_ri
519519

520520

521521
def stream_gripper_rgbd(*, is_rotate=True, ai_models_to_use: list[AIModelWrapper]|None=None, detect_aruco_marker_size: float|None=None, use_ros_for_cameras:bool=False) -> Generator[RGBDFrame, None, None]:
522-
for synced_frame in stream_gripper_camera(is_rotate=is_rotate, ai_models_to_use=ai_models_to_use, detect_aruco_marker_size=detect_aruco_marker_size, use_ros_for_cameras=use_ros_for_cameras, enable_pointcloud=True):
522+
try:
523+
calib = RGBCameraCalibration.load_calibration_from_fleet_path(
524+
RGBCameras.gripper_right, is_flip_width_and_height=False
525+
)
526+
camera_matrix = calib.camera_matrix
527+
except Exception as e:
528+
import logging
529+
logging.warning(f"Could not load calibration for gripper_right: {e}. Using fallback default intrinsics.")
530+
camera_matrix = np.array([
531+
[251.0758, 0.0, 201.3269],
532+
[0.0, 250.9491, 319.2119],
533+
[0.0, 0.0, 1.0]
534+
])
535+
536+
for synced_frame in stream_gripper_camera(is_rotate=is_rotate, ai_models_to_use=ai_models_to_use, detect_aruco_marker_size=detect_aruco_marker_size, use_ros_for_cameras=use_ros_for_cameras, enable_pointcloud=False):
523537
if synced_frame is None:
524538
continue
525539
image_frame = synced_frame.right
526540
if image_frame is None:
527541
continue
528542

529-
pointcloud = synced_frame.pointcloud if synced_frame.pointcloud is not None else np.zeros((0, 3))
530-
pointcloud_colors = synced_frame.pointcloud_color if synced_frame.pointcloud_color is not None else np.zeros((0, 3))
531543
depth_image = synced_frame.depth if synced_frame.depth is not None else np.zeros((0, 0))
544+
if synced_frame.pointcloud is not None:
545+
pointcloud = synced_frame.pointcloud
546+
pointcloud_colors = synced_frame.pointcloud_color
547+
elif depth_image.size > 0:
548+
fx = camera_matrix[0, 0]
549+
fy = camera_matrix[1, 1]
550+
cx = camera_matrix[0, 2]
551+
cy = camera_matrix[1, 2]
552+
553+
h, w = depth_image.shape
554+
v, u = np.meshgrid(np.arange(h), np.arange(w), indexing='ij')
555+
556+
valid_mask = depth_image > 0
557+
z = depth_image[valid_mask].astype(np.float32) / 1000.0 # mm to meters
558+
559+
u_valid = u[valid_mask]
560+
v_valid = v[valid_mask]
561+
562+
x = (u_valid - cx) * z / fx
563+
y = (v_valid - cy) * z / fy
564+
565+
pointcloud = np.stack((x, y, z), axis=-1)
566+
567+
rgb_image = image_frame.image
568+
if rgb_image is not None and rgb_image.ndim == 3:
569+
pointcloud_colors = rgb_image[valid_mask][:, ::-1] # BGR to RGB
570+
else:
571+
pointcloud_colors = np.zeros((len(pointcloud), 3))
572+
else:
573+
pointcloud = np.zeros((0, 3))
574+
pointcloud_colors = np.zeros((0, 3))
532575

533576
yield RGBDFrame(
534577
timestamp=synced_frame.timestamp,

0 commit comments

Comments
 (0)