1. ROS+opencv application

ROS transmits images in its own sensor_msgs/Image message format and cannot directly perform image processing, but the provided [CvBridge] can perfectly convert and be converted image data formats. [CvBridge] is a ROS library, equivalent to the bridge between ROS and Opencv.

Opencv and ROS image data conversion is shown in the figure below:

image-20230620143009969

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 set up the camera driver environment and the color images, depth images and infrared IR images that can be viewed. We can first check what topics are published and what the content of the image data is after driving the camera. Enter the following command in the terminal to start the camera,

Then, view the topic data list through the following command,

image-20231103183747667

Among them, /camera/color/image_raw and /camera/depth/image_raw are the data of color image and depth image. You can use the following command to view the data content of a certain frame.

Color image:

image-20230620144515096

Depth map:

image-20230620144542767

There is an important value here: encoding, which represents the encoding format of the image and 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

image-20230620145143404

View topic communication between nodes, terminal input,

image-20230620152347159

1.2.2. Core code analysis

Code reference path:

The /get_astra_rgb_node node subscribes to the topic of /camera/color/image_raw, and then uses data conversion to convert the topic data into image data and publish it. The code is as follows,

1.3. Subscribe to depth image topic information and display depth images

1.3.1. Run command

image-20230620152906166

View topic communication between nodes, terminal input,

image-20230620153004006

1.3.2. Core code analysis

Code reference path:

The basic implementation process is the same as RGB color image display. It subscribes to the topic data of /camera/depth/image_raw published by the depth camera node, and then converts it into image data through data conversion. The code is as follows,