3. ROS+Opencv foundation

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

3.1. Overview

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

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

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

Feature pack location: ~/yahboomcar_ws/src/yahboomcar_visual

ROS has already integrated versions above Opencv3.0 during the installation process, so the installation configuration hardly needs to be considered too much. 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, equivalent to a bridge between ROS and Opencv.

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

image-20210903091159912

Although the installation configuration does not need to be considered too much, the use environment still needs to be configured, mainly the two files [package.xml] and [CMakeLists.txt]. This function package not only uses [CvBridge], but also needs [Opencv] and [PCL], so it is configured together.

Add the following

[cv_bridge]: Image conversion dependency package.

There are many configuration contents in this file. For details, please refer to the source file.

3.2. Monocular camera/Raspberry PI CSI camera

3.2.1. Start Monocular camera/Raspberry PI CSI camera

View threads

You can see a lot of topics, just a few commonly used in this section

topic nametype of data
/usb_cam/image_rawsensor_msgs/Image
/usb_cam/image_raw/compressedDepthsensor_msgs/Image
/usb_cam/image_raw/compressedsensor_msgs/Image

Check the encoding format of the topic: rostopic echo +[topic]+encoding, for example

image-20210903120844654

The topic with [compressed] or [compressedDepth] after the topic is a compressed topic. When ROS transmits images, data packets may be lost due to factors such as the network, the running speed of the host, the running memory of the host, and the huge amount of video stream data. off topic. So there is no way, I can only subscribe to the compressed topic. Open two images at the same time to subscribe to different topics for testing. If the device performance is good and the network is also good, there will be no change. Otherwise, you will find that the topics after image compression will be much smoother.

image-20210903140543123

3.2.2. Start the color map subscription node

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

  1. Create subscribers

The subscribed topic is ["/usb_cam/image_raw"], the data type is [Image], and the callback function [topic()].

The topic of subscription is ["/usb_cam/image_raw/compressed"], data type [CompressedImage], and callback function [compressed_topic()].

  1. Create a publisher

The published topic is ["/usb_cam/image_flip"], data type [Image], queue size [10].

The posted topic is ["/usb_cam/image_flip/compressed"], data type [CompressedImage], queue size [10].

  1. Callback function

3.3、Jetson CSI camera

3.3.1. Start Jetson CSI camera

View threads

You can see a lot of topics, just a few commonly used in this section

topic nametype of data
/usb_cam/image_rawsensor_msgs/Image
/usb_cam/image_raw/compressedsensor_msgs/Image

Check the encoding format of the topic: rostopic echo +[topic]+encoding, for example

image-20210903120844654

The topic with [compressed] or [compressedDepth] after the topic is a compressed topic. When ROS transmits images, data packets may be lost due to factors such as the network, the running speed of the host, the running memory of the host, and the huge amount of video stream data. off topic. So there is no way, I can only subscribe to the compressed topic. Open two images at the same time to subscribe to different topics for testing. If the device performance is good and the network is also good, there will be no change. Otherwise, you will find that the topics after image compression will be much smoother.

image-20210903140543123

3.2.2. Start the color map subscription node

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

  1. Create subscribers

The subscribed topic is ["/csi_cam_0/image_raw"], the data type is [Image], and the callback function [topic()].

The topic of subscription is ["/csi_cam_0/image_raw/compressed"], data type [CompressedImage], and callback function [compressed_topic()].

  1. Create a publisher

The published topic is ["/csi_cam_0/image_flip"], data type [Image], queue size [10].

The posted topic is ["/csi_cam_0/image_flip/compressed"], data type [CompressedImage], queue size [10].

  1. Callback function