2、ROS+opencv application

This lesson uses a usb no-drive camera as an example

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

 

 

 

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

Run Command

 

Related points to note:

1、Before entering the docker container, make sure whether the usb no-drive camera device is connected, and add the camera device in the startup script. For the specific tutorial, please see [docker Tutorial ——5、Entering docker Container]

2、Due to the performance of some motherboards is not very good, running the usb camera topic node GUI display will be very card (such as jetson nano), can run the node without image display, and then use the rgt_image_view tool in the following tutorial to view the image

 

View the node communication diagram

Docker terminal input

image-20230425173134021

When you run the node directive without image display, the /examine_Image node is not displayed in rgt_graph

 

View topic list

Check which image topics are published, enter in 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.

notes: Sometimes the first loading after selecting the topic is not out, you can end the process and re-enter the command to enter the interface to display the image

 

2.2、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.