3.ROS+Opencv basics

3.1、Overview

ROS has already integrated Opencv3.0 and above during the installation process, so there is almost no need to think too much about the installation configuration.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-20231016181447397

Although the installation configuration does not require too much consideration, the usage environment still needs to be configured, mainly the two files [package.xml] and [CMakeLists.txt]. This function package not only uses [CvBridge], but also requires [Opencv] and [PCL], so they are configured together.

3.2 Start USB camera

Terminal input,

View topics

image-20231016181841522

Commonly used ones are /usb_cam/image_raw and /usb_cam/image_raw/compressed. The former is a normal image, and the latter is a compressed image.

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

image-20231016182212833

3.3 Start the color picture subscription node

3.4 View the node graph

Terminal input,

image-20231016182814425

3.5 Source code

Source code location:/home/yahboom/dofbot_ws/src/dofbot_visual/src/get_rgb_image.cpp