Welcome to DOFBOT-Ultra repository
2. Deep pseudo-color image
Deep Pseudo-Color Image
Please ensure that the web control program backend process is not running in the background. To close it, refer to the [Get Started Quickly - 2. Access the Terminal] section in [Disable the Auto-Start Web Control Backend Process]. After closing, please restart DofbotUltra!!!
Before starting this function, you need to close the web control program backend process.
1. Principle Introduction
After the program starts, it converts the subscribed black-and-white depth image into a pseudo-color image. Based on the distance information from the depth data, the image presents different levels of color.
2. Running the Demo
Enter in the terminal:
xxxxxxxxxx# Start the cameraros2 launch orbbec_camera dabai_dcw2.launch.py# Start the depth-to-pseudo-color image programros2 run dofbot_ultra_depth depth_to_colorAfter successful startup as shown in the figure below, a window will be generated displaying the pseudo-color image,

From the actual distance, the depth information differences are intuitively reflected by colors.
3. Program Flowchart

4. Core Code Analysis
The code path is as follows:
xxxxxxxxxxRaspberry Pi: /home/yahboom/dofbot_ultra_ws/src/dofbot_ultra_depth/dofbot_ultra_depth/depth_to_color.pyRDK: /home/sunrise/dofbot_ultra_ws/src/3d/dofbot_ultra_depth/dofbot_ultra_depth/depth_to_color.py
Code analysis:
Import necessary libraries:
xxxxxxxxxx#ros2py libraryimport rclpyfrom rclpy.node import Node#opencv image processing libraryimport cv2 as cv#cv_bridge library, used for conversion between message data and image datafrom cv_bridge import CvBridge#Import image data message typefrom sensor_msgs.msg import ImageDefine image encoding format:
xxxxxxxxxxencoding = ['16UC1', '32FC1']
Create subscriber and CvBridge object:
xxxxxxxxxx#define a subscriber, subscribe to /camera/depth/image_raw topic message data, callback function is topicself.sub = self.create_subscription(Image, '/camera/depth/image_raw', self.topic, 10)self.depth_bridge = CvBridge()Callback function, specifically handles received image message data, converts image and displays it:
xxxxxxxxxxdef topic(self,msg): #Use the imgmsg_to_cv2 method of the created depth_bridge to convert received message msg data into image data. The input parameters are the received msg data and the image encoding format, here the value is '32FC1' depth_image_orin = self.depth_bridge.imgmsg_to_cv2(msg, encoding[1]) #Call the applyColorMap method in opencv to convert the depth image from the previous step into a pseudo-color image. The input parameters are the depth image scaled proportionally and the color mapping type depth_to_color_image = cv.applyColorMap(cv.convertScaleAbs(depth_image_orin, alpha=0.03), cv.COLORMAP_JET) #Display image cv.imshow(self.window_name, depth_to_color_image) cv.waitKey(1)cv.convertScaleAbs: Used for processing images to enhance contrast or adjust brightness. Input parameters are:
frame: Input image, usually a
numpyarray.alpha: Scaling factor, default is 1. It affects pixel value scaling.
cv.applyColorMap: A function that applies pseudo-color mapping to grayscale images, which can enhance the visualization effect of images. Input parameters are:
frame: Input grayscale image, usually a single-channel
numpyarray.colormap: Color mapping type, the following options are available for different effects:
COLORMAP_AUTUMN: Gradient from black to red.
COLORMAP_BONE: Gradient from gray to blue.
COLORMAP_JET: Gradient from blue to red, commonly used for heatmaps.
COLORMAP_WINTER: Gradient from blue to green.
COLORMAP_RAINBOW: Rainbow color gradient.
COLORMAP_OCEAN: Gradient from deep blue to light blue.
COLORMAP_SUMMER: Gradient from green to yellow.
COLORMAP_SPRING: Gradient from pink to yellow.
COLORMAP_COOL: Gradient from cyan to pink.
COLORMAP_HSV: Gradient based on HSV color space.
COLORMAP_PINK: Gradient from black to pink.
COLORMAP_HOT: Gradient from black to red to yellow.
You can change the default COLORMAP_JET in the program to any of the above parameters to test different effects.