Welcome to NUWA-HP60C Depth Camera repository
1. ROS+OpenCV application
1. ROS+OpenCV application
ROS transmits images in its own sensor_msgs/Image message format and cannot directly process images, but the provided [CvBridge] can perfectly convert and be converted image data formats. [CvBridge] is a ROS library, which is equivalent to a bridge between ROS and Opencv.
The image data conversion between Opencv and ROS is shown in the figure below:

This lesson uses two cases to show how to use CvBridge for data conversion.
1.1, Camera topic data
In the previous section, we have built the camera driver environment and the color images, depth images and infrared IR images that can be seen. We can first check which topics are published and what the image data is after driving the camera. Enter the following command in the terminal to start the camera,
xxxxxxxxxx#Camera startupros2 launch ascamera hp60c.launch.pyThen, use the following command to view the topic data list,
xxxxxxxxxxros2 topic list

Among them, /ascamera_hp60c/camera_publisher/rgb0/image and /ascamera_hp60c/camera_publisher/depth0/image_raw are the data of color and depth images. You can use the following command to view the data content of a certain frame,
xxxxxxxxxx#View the RGB image topic data contentros2 topic echo /ascamera_hp60c/camera_publisher/rgb0/image#View the data content of the Depth image topicros2 topic echo /ascamera_hp60c/camera_publisher/depth0/image_rawColor image:

Depth image:

Here is a key value: encoding, which indicates the encoding format of the image, which needs to be referenced when converting image data later.
1.2. Subscribe to color image topic data and display color images
1.2.1. Run command
xxxxxxxxxx#Camera startupros2 launch ascamera hp60c.launch.pyros2 run yahboomcar_visual ascam_rgb_image
View the topic communication between nodes, terminal input,
xxxxxxxxxxros2 run rqt_graph rqt_graph

1.2.2, core code analysis
Code reference path:
xxxxxxxxxx~/ascam_ros2_ws/src/yahboomcar_visual/yahboomcar_visual/ascam_rgb_image.py/get_astra_rgb_node node subscribes to the topic of /ascamera_hp60c/camera_publisher/rgb0/image, and then converts the topic data into car image data through data conversion. The code is as follows,
xxxxxxxxxx#Import opecv library and cv_bridge libraryimport cv2 as cvfrom cv_bridge import CvBridge#Create CvBridge objectself.bridge = CvBridge()#Define a subscriber to subscribe to the RGB color image topic data published by the depth camera nodeself.sub_img=self.create_subscription(Image,'/ascamera_hp60c/camera_publisher/rgb0/image',self.handleTopic,100)#msg is converted into image data, where bgr8 is the image encoding formatframe = self.bridge.imgmsg_to_cv2(msg, "bgr8")1.3, Subscribe to the depth image topic information and display the depth image
1.3.1, Run command
xxxxxxxxxx#Camera launchros2 launch ascamera hp60c.launch.pyros2 run yahboomcar_visual ascam_depth_image
To view the topic communication between nodes, enter the terminal,
xxxxxxxxxxros2 run rqt_graph rqt_graph

1.3.2, core code analysis
Code reference path:
xxxxxxxxxx~/ascam_ros2_ws/src/yahboomcar_visual/yahboomcar_visual/ascam_depth_image.py
The basic implementation process is the same as the RGB color image display. It subscribes to the topic data of /ascamera_hp60c/camera_publisher/depth0/image_raw published by the depth camera node, and then converts it into image data through data conversion. The code is as follows,