Welcome to ROSMASTER A1 PRO repository
5.Depth Pseudo Color Image (Depth Camera Only)
🌈 Depth Pseudo Color Image Rendering (Depth to Color)
1. Course Content
By subscribing to the raw single-channel depth data from the Angstrong Nuwa-HP60C depth camera (/ascamera_hp60c/camera_publisher/depth0/image_raw), use OpenCV's colormap algorithm to perform pseudo-color rendering on the continuous depth space, generating a heatmap that intuitively reflects the depth of objects.
Important
This course is only applicable to users with the Angstrong Nuwa-HP60C Depth Camera version.
2. Preparation and Running
This case requires opening 2 terminals to start the camera driver and pseudo-color rendering node respectively:
2.1 Start Camera Low-level Driver
Run in Terminal 1:
ros2 launch ascamera hp60c.launch.py
2.2 Start Pseudo Color Image Rendering Node
Run in Terminal 2:
xxxxxxxxxxros2 run yahboomcar_depth depth_to_color
3. Core Source Code Analysis
Source Code Path:
xxxxxxxxxx$HOME/yahboomcar_ros2_ws/yahboomcar_ws/src/yahboomcar_depth/yahboomcar_depth/Basic/depth_to_color.py
xclass DepthToColor(Node): def __init__(self): super().__init__('depth_to_color') # 1. Subscribe to Nuwa depth image topic (16UC1 / 32FC1 millimeter unit) self.sub = self.create_subscription( Image, '/ascamera_hp60c/camera_publisher/depth0/image_raw', self.topic, 10) self.window_name = 'depth_image' self.depth_bridge = CvBridge()
def topic(self, msg): # 2. Convert ROS depth image to 32-bit single-precision floating point matrix depth_image_orin = self.depth_bridge.imgmsg_to_cv2(msg, '32FC1') # 3. Linear grayscale stretch and convert to 8-bit single-channel image (alpha adjusts contrast scaling) depth_scaled = cv.convertScaleAbs(depth_image_orin, alpha=0.45) # 4. Apply JET classic scientific pseudo-color mapping (red for near, blue for far) depth_to_color_image = cv.applyColorMap(depth_scaled, cv.COLORMAP_JET) # 5. Render and display cv.imshow(self.window_name, depth_to_color_image) cv.waitKey(1)3.1 OpenCV Common Colormap Description
cv.applyColorMap supports multiple classic pseudo-color palettes:
| Colormap Macro | Color Gradient Style | Applicable Scenario |
|---|---|---|
cv.COLORMAP_JET | Blue → Cyan → Yellow → Red (classic heatmap) | 3D depth camera depth visualization (default) |
cv.COLORMAP_VIRIDIS | Blue-purple → Green → Yellow (modern perceptually uniform colormap) | Scientific visualization and high contrast imaging |
cv.COLORMAP_HOT | Black → Red → Yellow → White | Thermal imaging and high dynamic temperature mapping |
cv.COLORMAP_BONE | Black → Blue-gray → White | Similar to X-ray grayscale medical style |
cv.COLORMAP_RAINBOW | Red → Orange → Yellow → Green → Blue → Purple | Rainbow color multi-band high contrast differentiation |