4、 ROS+Opencv basic course

This lesson takes the Astra camera as an example, the ordinary camera is similar.

4.1、Overview

Wiki:http://wiki.ros.org/cv_bridge/

Tutorials:http://wiki.ros.org/cv_bridge/Tutorials

Source code:https://github.com/ros-perception/vision_opencv.git

Function package path:~/transbot_ws/src/transbot_visual

【CvBridge】is a ROS library, equivalent to a bridge between ROS and Opencv. It can perfectly convert and be converted image data format.

Opencv and ROS image data conversion is shown below:

image-20210903091159912

This function package not only needs to use [CvBridge], but also needs [Opencv] and [PCL], so we need to perform the following configuration.

Add following content.

【cv_bridge】:Image conversion dependent package.

【transbot_msgs】:Custom message dependency package.

This file has a lot of configuration content, please check the source file for specific content.

4.2、Astra

4.2.1、Start up Astra camera

View topic

Common topics are as follows

Topic nameData type
/camera/depth/image_rawsensor_msgs/Image
/camera/depth/imagesensor_msgs/Image
/camera/rgb/image_rawsensor_msgs/Image
/camera/depth/image_raw/compressedDepthsensor_msgs/CompressedImage
/camera/rgb/image_raw/compressedsensor_msgs/CompressedImage

View the encoding format of the topic: rostopic echo +【topic】+encoding, for example

image-20210903120844654

image-20210903120710683

The topic with 【compressed】or 【compressedDepth】 at the end of the topic is a compressed topic. During image transmission, ROS may cause data packet loss due to factors such as the network, main control running speed, main control running memory, and huge video stream data. Unable to get topics, so we recommend users to use compressed topics.

image-20210903140543123

4.2.2、Start the color map subscription node

View node graph

image-20210903112012709

【/astra_rgb_Image_cpp】is the node we wrote.

Create subscribers: The subscribed topic is 【"/camera/rgb/image_raw"】, the data type is 【Image】, and the callback function is 【topic()】

Use 【CvBridge】 for data conversion to ensure that the encoding format is correct.

4.2.3、Start the depth map subscription node

View node graph

image-20210903141033399

Create subscribers: The subscribed topic is ["/camera/depth/image_raw"], the data type is [Image], and the callback function is [topic()]

Use 【CvBridge】 for data conversion to ensure that the encoding format is correct.

4.2.4、Start color image inversion

View node graph

image-20210903105043487

Two subscribers and two publishers are created here, one for processing general image data and one for processing compressed image data.

1)Create subscriber

The subscribed topic is【"/camera/rgb/image_raw"】,the data type is【Image】,and the callback function is【topic()】。

The subscribed topic is【"/camera/rgb/image_raw/compressed"】,the data type is【CompressedImage】,and the callback function is【compressed_topic()】。

2)Create publisher

The published topic is【"/camera/rgb/image_flip"】,the data type is【Image】,Queue size【10】。

The published topic is【"/camera/rgb/image_flip/compressed"】,the data type is【CompressedImage】,Queue size【10】。

3)Callback function

4.2.5、Publish image

Start up command as following content: