Depth → Point Cloud — ROS2 Example
Source: rbq_sdk/ros2/src/rbq_examples/src/depth_to_pcl.cpp
A ROS 2 node that converts each camera's depth image into a PointCloud2 using the camera intrinsics.
How it works
For each numeric sensor sensor_0–sensor_5 it:
- subscribes to
/rbq/vision/<sensor>/depth/compressed(sensor_msgs/CompressedImage, PNG-encoded16UC1) and/rbq/vision/<sensor>/depth/camera_info, - decodes the PNG depth frame (
cv::imdecodewithIMREAD_UNCHANGED) and deprojects each pixel with the pinhole model usingfx, fy, cx, cyfrom the camera info — depth is in millimeters (z = depth × 0.001), and zero-depth pixels becomeNaN, - publishes
/rbq/vision/<sensor>/pointcloud(sensor_msgs/PointCloud2, unorganized XYZ).
sensor_0–sensor_3 are the body depth cameras, sensor_4 is the front camera, and sensor_5 the rear. Uses OpenCV for the PNG depth decode.
Prerequisites
- ROS 2 Humble + RBQ ROS2 SDK built — see ROS2 SDK Overview.
- A publisher of the compressed depth streams — the robot's vision stack, or the MuJoCo simulator with vision (
bash scripts/sim.bash --vision). Both publish/rbq/vision/sensor_N/depth/compressedwith matchingcamera_info.
Build & run
bash
cd RBQ/rbq_sdk/ros2
colcon build --packages-up-to rbq_examples
source install/setup.bash
export RMW_IMPLEMENTATION=rmw_cyclonedds_cpp
ros2 run rbq_examples depth_to_pclInspect a resulting cloud, e.g. the front camera:
bash
ros2 topic echo --once /rbq/vision/sensor_4/pointcloud