2、ROS+opencv application

This lesson takes Astra cameras as an example, similar to regular cameras.

ROS with its own “sensor_ The msgs/Image” message format transmits images, which cannot be directly processed, but the provided 【CvBridge】can perfectly convert and convert image data formats. 【CvBridge】 is an ROS library that serves as a bridge between ROS and Opencv.

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

image-20230425150159148

This lesson uses three case studies to demonstrate how to use CvBridge for data conversion.

1、Astra camera

Before driving a depth camera, it is necessary for the host to be able to recognize the Astra camera device; When entering the Docker container, you need to mount this Astra device to recognize the camera in the Docker container. The supporting host has already been built in an environment and does not require additional configuration. If it is on a new host, a rule file needs to be added. The addition method is very simple. Copy the "/etc/udev. rules. d/56 orbbecusb. rules" file from the host computer to the "/etc/udev. rules. d" directory in the new environment, and then restart it once.

1.1.1、Start camera

Taking starting the Astrapro camera as an example, after entering the Docker container, the terminal inputs,

The corresponding camera model startup is shown in the table below,

image-20230425150702895

1.1.2、View camera topics

Dock terminal input,

image-20230425151009256

The main focus is on the topic of image data. Here, we only analyze the topic information of RGB color images and depth images. Use the following command to view the respective data information, and input the Dock terminal,

First, take a frame of RGB color image information and take a look,

image-20230425151837588

First, take a frame of RGB color image information and take a look. This explains the basic information of the image, an important value, 【encoding 】, where the value is 【 rgb8 】. This value indicates that the encoding format of this frame of image is rgb8, which needs to be referenced when performing data conversion later。

Similarly, below is the data information of a certain frame of the depth image,

image-20230425152618725

The encoding value here is 【 16UC1】.

2、Subscribe to RGB image topic information and display RGB images

2.1、Run Command

Docker terminal input,

image-20230425160141198

2.2、View node communication diagram

Docker terminal input,

image-20230425160632698

2.3、Core code parsing

Code reference path,

As can be seen from 2.2,/get_ Astra_ Rgb_ Node node subscribed to/camera/color/image_ Raw's topic, and then through data conversion, the topic data is converted into car image data for publishing. The code is as follows,

3、Subscribe to depth image topic information and display depth images

3.1、Run Command

image-20230425163605146

3.2、View node communication diagram

Docker terminal input,

image-20230425163901150

3.3、Core code parsing

Code reference path,

The basic implementation process is the same as RGB color image display, subscribed to the/camera/depth/image published by the depth camera node_ Raw's topic data is then converted into image data through data conversion, with the following code,

4、Subscribe to image data and publish the converted image data

4.1、Run Command

4.2、View node communication diagram

Docker terminal input,

image-20230425173134021

4.3、Viewing Topic Data

First, check which image topics have been published and input them through the Docker terminal,

image-20230425175046734

The/image is the topic data we have published. Use the following command to print and view the data content of this topic,

image-20230425175257775

You can use rqt_ Image_ View tool to view images,

image-20230425175651680

After opening, select the topic name/image in the upper left corner to view the image.

4.4、Core code parsing

code path,

The implementation steps are roughly the same as the previous two, and the program first subscribed to/image_ Raw's topic data is then converted into image data, but here we also perform lattice transformation to convert image data into topic data and publish it, which is image topic data ->image data ->image topic data.