yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
RDK X5 Robot📖
01. RDK-X5-Robot Introduction
  • 1.Introduction
  • 2.Common Problem Analysis
  • 3.Battery and charger usage precautions
  • 4.TF card expand capacity
02. Assembly Tutorial
  • Assembly Tutorial
  • Assembly Video-1
  • Assembly Video-2
  • Assembly Video-3
  • Assembly Video-4
03. Remote Control Course
  • 1.Mobile APP remote control
  • 2.USB Wireless Controller Remote Control
04. ROS Driver Board Course
  • 1. Introduction of extension board
  • 2. Set up STM32 development environment
  • 3. Key control buzzer sound
  • 4. FreeRTOS application
  • 5. Serial communication
  • 6. SBUS model remote control
  • 7. CAN bus communication
  • 8. RGB color light strip
  • 9. Timer interrupt control PWM servo
  • 10. Control serial steering gear
  • 11. Nine-axis attitude sensor to obtain data
  • 12. Control motor forward and reverse
  • 13. The timer captures encoder data
  • 14. Theory of robot kinematics analysis
  • 15. PID control robot motion
05. Basic Control Course
  • 1.Update expansion board firmware
  • 2.Install Python driver library
  • 3.Set the car type
  • 4.Open and close APP program control
  • 5.Turn hotspot mode on and off
  • 6.Buzzer sound
  • 7.Control the motor to rotate forward and reverse
  • 8.Controlling robot movement
  • 9.OLED display
  • 10.Control fans and lighting effects
06. Development Environment
  • 1. Virtual machine installation and use
  • 2. Linux Basics
  • 3. Remote connection
  • 4. Multi-machine communication configuration
  • 5. Bind device ID
  • 6. Image installation and backup
07. ROS2 Basic Course
  • 1. Introduction to ROS2
  • 2. ROS2 install Humble
  • 3. ROS2 development environment
  • 4. ROS2 workspace
  • 5. ROS2 function package
  • 6. ROS2 node
  • 7. ROS2 topic communication
  • 8. ROS2 service communication
  • 9. ROS2 action communication
  • 10. ROS2 custom interface message
  • 11. ROS2 parameter service case
  • 12. ROS2 meta-function package
  • 13. ROS2 distributed communication
  • 14. ROS2 DDS
  • 15. ROS2 time related API
  • 16. ROS2 common command tools
  • 17. ROS2 rviz2 use
  • 18. ROS2 rqt toolbox
  • 19. ROS2 Launch startup file configuration
  • 20. ROS2 recording and playback tool
  • 21. ROS2 URDF model
  • 22. ROS2 Gazebo simulation platform
  • 23. ROS2 TF2 coordinate transformation
08. Robot Chassis Control Course
  • 1. PID algorithm theory
  • 2. Robot information release
  • 3. Robot control
  • 4. Robot state estimation
  • 5. Robot calibration
  • 6. Robot trajectory tracking
  • 7. URDF Model
09. LiDAR Course
  • 1. Introduction and use of lidar
  • 2. Lidar obstacle avoidance
  • 3. Lidar tracking
  • 4. Lidar guard
  • 5. Lidar patrol
  • 6. gmapping mapping algorithm
  • 7. Cartographer mapping algorithm
  • 8. Navigation and obstacle avoidance
  • 9. App Mapping and Navigation
10. OpenCV Course
  • 1. Getting started with OpenCV
  • 2. OpenCV geometric transformation
  • 3. OpenCV Image Processing
  • 4. OpenCV image beautification
  • 5. QR code creation and recognition
11. Mipi Camera Course
  • 1. Camera driver
  • 2. Adjust the color HSV value
  • 3. Color recognition
  • 4. Color Tracking
  • 5. Color Follow
  • 6. QR code instructions
  • 7. Face Detection
  • 8. Object Detection
  • 9. Visual line patrol-OpenCV
  • 10. Visual line patrol-deep learning
  • 11. Human body tracking
  • 12. Gesture control
12. Depth Camera Course
  • 1. Use of Depth Camera
  • 2. Camera intrinsic calibration
  • 3. ROS+OpenCV Basics
  • 4. AR Vision
  • 5. Color Tracking
  • 6. Object Tracking
  • 7. RTAB-Map 3D Mapping Navigation
13. Multi-robot Synchronous Control
  • Multi-vehicle synchronous control
Remote login control
  • 1. VNC and SSH remote login
  • 2. Jupyter lab login and case code running
Download
  • System_File
  • Code
  • VM_File
  • Software_Tools
  • Hardware_Info
  • Firmware
  • Instruction_Manual
  • ROS2_Basic_VM
Download ZIP

Welcome to RDK X5 Robot repository

3. ROS+OpenCV Basics

ROS+OpenCV Basics

ROS+OpenCV Basics3.1、Program Function Description3.2, Program code reference path3.3, Start the camera3.4, subscribe to RGB image topic information and publish converted image data3.4.1, node startup3.4.2, View the node communication graph3.4.3, core source code analysis3.5, Subscribe to Depth image topic information and publish the converted image data3.5.1, Node startup3.5.2, View the node communication graph3.5.3, Core source code analysis

3.1、Program Function Description

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, which is equivalent to a bridge between ROS and OpenCV.

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

1684988437924

The following takes the Astra pro camera as an example, using two cases to show how to use CvBridge for data conversion and use the ROSboard web page to display topic data.

3.2, Program code reference path

After SSH connects to the car, the source code of this function is located at,

xxxxxxxxxx
#RGB image example
/home/sunrise/yahboomcar_ws/src/yahboomcar_astra/yahboomcar_imshow/yahboomcar_imshow/astra_rgb_image.py
#Depth image example
/home/sunrise/yahboomcar_ws/src/yahboomcar_astra/yahboomcar_imshow/yahboomcar_imshow/astra_depth_image.py

3.3, Start the camera

After SSH connects to the car, enter in the terminal,

xxxxxxxxxx
ros2 launch astra_camera astro_pro_plus.launch.xml

View the topic through the following command, enter in the virtual machine terminal,

xxxxxxxxxx
ros2 topic list

image-20241114144047687

The main thing to look at is the image data topic. Here, only the RGB color image and Depth depth image topic information are parsed. Use the following command to view the respective data information. Enter the virtual machine terminal,

xxxxxxxxxx
#View the RGB image topic data content
ros2 topic echo /camera/color/image_raw

You can intercept a frame of RGB color image information,

image-20241114144151384

Here is the basic information of the image, an important value, encoding, the value here is rgb8, indicating that the encoding format of this frame of image is rgb8, which needs to be referred to when doing data conversion later.

Input in the virtual machine terminal,

xxxxxxxxxx
#View the data content of the Depth image topic
ros2 topic echo /camera/depth/image_raw

Intercept the image data information of a certain frame of the depth image,

image-20241114144222743

The encoding value here is 16UC1.

3.4, subscribe to RGB image topic information and publish converted image data

3.4.1, node startup

After SSH connects to the car and starts the camera, input in the terminal: You need to start the camera first and then enter the following command

xxxxxxxxxx
#RGB color image display node
ros2 run yahboomcar_imshow astra_rgb_image

Input in the car terminal,

xxxxxxxxxx
#Start ROSboard
ros2 run rosboard rosboard_node

Open the browser on the PC (note that the computer and the Sunrise Network must be in the same LAN), enter the URL: car IP:9999, for example, my car IP is 192.168.2.84, enter the URL in the browser on the virtual machine to open the ROSboard web page:

xxxxxxxxxx
192.168.2.84:9999

image-20241114144750775

Select the /camera/color/image_raw and /cv_image/rgb topics, and you can see the following screen,

image-20241114144847672

The two images are the same and synchronized, except that the /cv_image/rgb image has the "cv_rgb" character.

1684997288576

3.4.2, View the node communication graph

Virtual machine terminal input,

xxxxxxxxxx
ros2 run rqt_graph rqt_graph

image-20241114145149775

3.4.3, core source code analysis

Code reference path,

xxxxxxxxxx
/home/sunrise/yahboomcar_ws/src/yahboomcar_astra/yahboomcar_imshow/yahboomcar_imshow/astra_rgb_image.py

From 3.2.2, we can see that the /get_astra_rgb_node node subscribes to the topic of /camera/color/image_raw, and then converts the ROS topic data into opencv image data through CvBridge. After being processed by opencv, the processed image data is converted into ROS topic data through CvBridge and published, that is, ROS topic data->opencv image data->ROS topic data. The code is as follows,

xxxxxxxxxx
# Import opecv library and cv_bridge library
import cv2 as cv
from cv_bridge import CvBridge

# Create CvBridge object
self.bridge = CvBridge()
# Define a subscriber to subscribe to the RGB color image topic data published by the depth camera node
self.sub_img = self.create_subscription(Image,'/camera/color/image_raw',self.handleTopic,1)
# Define a publisher to publish processed image topic data
self.pub_img = self.create_publisher(Image,'/cv_image/rgb',10)

# Convert msg to cv image data, where bgr8 is the image encoding format
frame = self.bridge.imgmsg_to_cv2(msg, "bgr8")
# Standardize input image size
frame = cv.resize(frame, (640, 480))
# Add characters to the image
cv.putText(frame, "cv_rgb", (280, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (0, 0, 255), 2)
# Convert the processed cv image data to msg data
msg = self.bridge.cv2_to_imgmsg(frame, "bgr8")
# Publish the converted image
self.pub_img.publish(msg)

3.5, Subscribe to Depth image topic information and publish the converted image data

3.5.1, Node startup

After SSH connects to the car and starts the camera, enter the terminal: You need to start the camera first and then enter the following command

xxxxxxxxxx
#Depth image display node
ros2 run yahboomcar_imshow astra_depth_image

Car terminal input,

xxxxxxxxxx
#Start ROSboard
ros2 run rosboard rosboard_node

Open the browser on the PC (note that the computer and the Sunrise Network must be in the same LAN), enter the URL: car IP:9999, for example, my car IP is 192.168.2.84, enter the URL in the browser on the virtual machine to open the ROSboard web page:

xxxxxxxxxx
192.168.2.84:9999

image-20241114144750775

Select /camera/depth/image_raw and /cv_image/depth topics, and you can see the following screen,

image-20241114145448457

The two images are the same and synchronized, except that the /cv_image/depth image has the "cv_depth" character.

image-20241114145535858

3.5.2, View the node communication graph

Virtual machine terminal input,

xxxxxxxxxx
ros2 run rqt_graph rqt_graph

image-20241114145657119

3.5.3, Core source code analysis

Code reference path,

xxxxxxxxxx
/home/sunrise/yahboomcar_ws/src/yahboomcar_astra/yahboomcar_imshow/yahboomcar_imshow/astra_depth_image.py

The basic implementation process is the same as the RGB color image display. It subscribes to the topic data of /camera/depth/image_raw published by the depth camera node, and then completes the conversion of ROS topic data->opencv image data->ROS topic data through CvBridge. The code is as follows,

xxxxxxxxxx
# Import opecv library and cv_bridge library
import cv2 as cv
from cv_bridge import CvBridge

# Create CvBridge object
self.bridge = CvBridge()
# Define a subscriber to subscribe to the depth image topic data published by the depth camera node
self.sub_img = self.create_subscription(Image,'/camera/depth/image_raw',self.handleTopic,1)
# Define a publisher to publish processed image topic data
self.pub_img = self.create_publisher(Image,'/cv_image/depth',10)

# Convert msg to cv image data, where 16UC1 is the image encoding format
frame = self.bridge.imgmsg_to_cv2(msg, "16UC1")
# Standardize input image size
frame = cv.resize(frame, (640, 480))
# Add text to the image
cv.putText(frame, "cv_depth", (280, 30), cv.FONT_HERSHEY_SIMPLEX, 1, (65536, 65536, 65536), 2)
# Convert the processed cv image data to msg data
msg = self.bridge.cv2_to_imgmsg(frame, "16UC1")
# Publish the converted image
self.pub_img.publish(msg)

 

Camera intrinsic calibration
AR Vision

COMPANY

  • About us
  • Team Style
  • Blog

LEARNING & EXPLORATION

  • Tutorials
  • Edge AI hardware
  • Educational robots
  • Embedded intelligent hardware

WHERE TO BUY

  • Yahboom Online Store
  • Amazon
  • Alibaba
  • AliExpress
  • Mercado

TECHNOLOGY SUPPORT

  • Email: support@yahboom.com

BE A DISTRIBUTOR

  • Email: sales@yahboom.com
QR Code

Copyright © 2017-2026 Yahboom. All Rights Reserved.

EN/中文