3. ROS+Opencv basics

3. ROS+Opencv basics3.1. Overview3.2 Gemini23.2.1. Start the Gemini2 camera3.2.2. Start the color graph subscription node3.2.3. Start the depth map subscription node3.2.4 Start color image inversion

This lesson uses the Gemini2 camera as an example, which is similar to a normal camera.

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 package location: ~/astra_ws/src/astra_visual

ROS has been integrated with Opencv3.0 and above during the installation process, so the installation and configuration hardly need to be considered. ROS in their own

message format Image, not directly to Image processing, However, the provided [CvBridge] can perfectly convert and be converted image data formats. [CvBridge] is a ROS library that acts as a bridge between ROS and Opencv.

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

image-20210903091159912

Although the installation configuration does not need to be much thought, but the use of the environment still need to be configured, mainly 【package.xml】 and 【CMakeLists.txt】 these two files. The function pack not only uses [CvBridge], but also needs [Opencv] and [PCL], so it is configured together.

Add the following

[cv_bridge] : Image conversion dependency package.

【transbot_msgs】 : Custom message dependency package.

This file contains many configurations. For details, see the source file.

3.2 Gemini2

3.2.1. Start the Gemini2 camera

View topic

image-20230612171953905

As you can see, there are many topics, but only a few are commonly used in this section

Topic nameData type
/camera/depth/image_rawsensor_msgs/Image
/camera/rgb/image_rawsensor_msgs/Image
/camera/ir/image_rawsensor_msgs/Image
/camera/depth/pointssensor_msgs/PointCloud2

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

image-20230612172330989

image-20230612172353069

3.2.2. Start the color graph subscription node

Select 1 of the following two nodes to start the launch file.

image-20230612172904788

View node diagram

image-20230612172936069

Create a subscriber: Subscribe to the topic ["/camera/rgb/image_raw"], data type [Image], callback function [topic()]

Use [CvBridge] for data conversion, here we should pay attention to the encoding format, the encoding format is wrong, the converted image will have problems.

Similar to py code

3.2.3. Start the depth map subscription node

image-20230612173414928

Select 1 of the following two nodes to start the launch file.

View node diagram

image-20230612173115014

Create a subscriber: Subscribe to the topic ["/camera/depth/image_raw"], data type [Image], callback function [topic()]

Use [CvBridge] for data conversion, here we should pay attention to the encoding format, the encoding format is wrong, the converted image will have problems.

Similar to py code

3.2.4 Start color image inversion

Image viewing

image-20230612173638903

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

1) Create subscribers

Subscribe to the topic ["/camera/rgb/image_raw"], data type [Image], callback function [topic()].

2) Create a publisher

The topics published are ["/camera/rgb/image_flip"], data type [Image], queue size [10].

3) Callback function