yahboom
HomeTutorialsProduct
Solution
Blog
Online Store
About Us
EN/中文
Store
Raspberry Pi 4B📖
1.Preparation before use
  • 1.1 Download image
  • 1.2 Write image into SD card
  • 1.3 Start up Raspberry Pi
  • 1.4 Linux common commands
  • 1.5 Precautions
2.Basic course
  • 2.1 Log into Raspberry Pi system
  • 2.2 Change password and root account
  • 2.3 Remote transfer file
  • 2.4 Backup image file
  • 2.5 Fixing Raspberry Pi IP
  • 2.6 Set screen keep on
  • 2.7 Get Pi temperature
  • 2.8 Connect WIFI
  • 2.9 Modify Pi time
  • 2.10 Set the boot self-starting program
3.Expand course
  • 3.1 Serial port communicates with external devices
  • 3.2 2.Serial port login Pi
  • 3.3 Configured as a router
  • 3.4 Install Jupyter Lab
  • 3.5 Install Jupyter Widgets
  • 3.6 More Detail for Widgets
  • 3.7 Install OpenCV
  • 3.8 Install Tensorflow
4.Programming course
C language
  • 1.Development environment
  • 2.Print Hello World
  • 3.Pin output level
  • 4.Read pin level
  • 5.PWM output
Python language
  • 1.Development environment
  • 2.Print basic usage
  • 3.Pin output level
  • 4.Read pin level
  • 5.PWM output
5.AI vision course
A.Getting started with OpenCV
  • 6.Picture Rotation
  • 1.Introduction of OpenCV
  • 2.OpenCV image read and display
  • 3.OpenCV image write
  • 4.OpenCV image quality
  • 5.OpenCV pixel operation
B.OpenCV Geometric transformat
  • 1.Picture Zoom
  • 2.Picture Cut
  • 3.Picture Shift
  • 4.Picture Mirroring
  • 5.Affine Map
  • 7.Perspective Transformation
C.OpenCV picture processing
  • 1.Grayscale processing
  • 2.Image Binarization
  • 3.Edge detection
  • 4.Drawing line segment
  • 5.Drawing rectangle circle
  • 6.Drawing text picture
D.OpenCV image beautification
  • 1.Histogram of color pictures
  • 2.Histogram equalization
  • 3.Image restoration
  • 4.Brightness enhancement
  • 5.Skin whitening
  • 6.Gaussian mean filtering
  • 7.Median filtering
E.Install TensorFlow
  • Install TensorFlow
F.AI Advanced Course (Ubuntu system)
  • 1. QR code
  • 2. Human posture estimation
  • 3. Target detection
  • 4. Mediapipe development
  • 5. yolov4-tiny
6.ROS1 coursenew
Basic Course
  • 1.ROS introduction
  • 2.Project file structure
  • 3.Common commands and tools
  • 4.Publisher
  • 5.Subscribers
  • 6.Customize topic messages and use
  • 7.Client
  • 8.Server
  • 9.Custom service messages and usage
  • 10.TF release and monitoring
Visual Image Processing
  • 1. AR vision
  • 2. AR QR code
  • 3. ROS+Opencv foundation
  • 4. ROS+Opencv application
  • 5. MediaPipe development
7.ROS2 coursenew
Basic Course
  • 1.Introduction to ROS2
  • 2.Commands and tools
  • 3.ROS2 Topic communications
  • 4.ROS2 service communications
  • 5.ROS2launch file starts
Docker Course
  • 1.Overview and installation
  • 2.Common commands
  • 3.Understand and publish images
  • 4.Hardware interaction data processing
  • 5.Enter docker container
  • 6.Update docker images
OpenCV Course
  • 1.OpenCV Basic Course
  • 2.ROS+opencv application
  • 3.QR code recognition
  • 4.AR Vision
  • 5.Mediapipe
8.Accessories installation
  • 1. Installation of heat sink
  • 2. Wiring of cooling fan
  • 3. Double fan armor case Installation
  • 4. Argon NEO aluminum case installation
  • 5. Argon ONE aluminum alloy case installation
  • 6. Metal shell with built-in fan installation
  • 7. Acrylic case with cooling fan installation
  • 8. White-red ABS protective case installation
Download
  • Tools
  • C_code
  • Python code
  • ROS System
Download ZIP

Welcome to Raspberry Pi 4B repository

3. ROS+Opencv foundation

3. ROS+Opencv foundation

3. ROS+Opencv foundation 3.1. Overview 3.2. Monocular camera/Raspberry PI CSI camera3.2.1. Start Monocular camera/Raspberry PI CSI camera3.2.2. Start the color map subscription node 3.3、Jetson CSI camera3.3.1. Start Jetson CSI camera3.2.2. Start the color map subscription node

This lesson takes the Astra camera as an example, which is similar to ordinary cameras.

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 pack location: ~/yahboomcar_ws/src/yahboomcar_visual

ROS has already integrated versions above Opencv3.0 during the installation process, so the installation configuration hardly needs to be considered too much. 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, equivalent to a bridge between ROS and Opencv.

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

image-20210903091159912

Although the installation configuration does not need to be considered too much, the use environment still needs to be configured, mainly the two files [package.xml] and [CMakeLists.txt]. This function package not only uses [CvBridge], but also needs [Opencv] and [PCL], so it is configured together.

  • package.xml

Add the following

​x
  < build_depend > sensor_msgs </ build_depend > 
  < build_export_depend > sensor_msgs </ build_export_depend > 
  < exec_depend > sensor_msgs </ exec_depend > 

  < build_depend > std_msgs </ build_depend > 
  < build_export_depend > std_msgs </ build_export_depend > 
  < exec_depend > std_msgs </ exec_depend > 
  < build_depend > cv_bridge </ build_depend > 
  < build_export_depend > cv_bridge </ build_export_depend > 
  < exec_depend > cv_bridge </ exec_depend > 
  < exec_depend > image_transport </ exec_depend > 

[cv_bridge]: Image conversion dependency package.

  • CMakeLists.txt

There are many configuration contents in this file. For details, please refer to the source file.

3.2. Monocular camera/Raspberry PI CSI camera

3.2.1. Start Monocular camera/Raspberry PI CSI camera

xxxxxxxxxx
roslaunch usb_cam usb_cam-test.launch

View threads

xxxxxxxxxx
rostopic list 

You can see a lot of topics, just a few commonly used in this section

topic nametype of data
/usb_cam/image_rawsensor_msgs/Image
/usb_cam/image_raw/compressedDepthsensor_msgs/Image
/usb_cam/image_raw/compressedsensor_msgs/Image

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

xxxxxxxxxx
rostopic echo /usb_cam/image_raw/encoding

image-20210903120844654

The topic with [compressed] or [compressedDepth] after the topic is a compressed topic. When ROS transmits images, data packets may be lost due to factors such as the network, the running speed of the host, the running memory of the host, and the huge amount of video stream data. off topic. So there is no way, I can only subscribe to the compressed topic. Open two images at the same time to subscribe to different topics for testing. If the device performance is good and the network is also good, there will be no change. Otherwise, you will find that the topics after image compression will be much smoother.

image-20210903140543123

3.2.2. Start the color map subscription node

xxxxxxxxxx
roslaunch yahboomcar_visual usb_cam_flip.launch 
  • In this case, you need to change usb_cam_flip_usb.py to usb_cam_flip.py

    image-20210903112012709

  • py code analysis

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

  1. Create subscribers

The subscribed topic is ["/usb_cam/image_raw"], the data type is [Image], and the callback function [topic()].

The topic of subscription is ["/usb_cam/image_raw/compressed"], data type [CompressedImage], and callback function [compressed_topic()].

  1. Create a publisher

The published topic is ["/usb_cam/image_flip"], data type [Image], queue size [10].

The posted topic is ["/usb_cam/image_flip/compressed"], data type [CompressedImage], queue size [10].

xxxxxxxxxx
sub_img = rospy.Subscriber("/usb_cam/image_raw", Image, topic)
pub_img = rospy.Publisher("/usb_cam/image_flip", Image, queue_size=10)
sub_comimg = rospy.Subscriber("/usb_cam/image_raw/compressed", CompressedImage, compressed_topic)
pub_comimg = rospy.Publisher("/usb_cam/image_flip/compressed", CompressedImage, queue_size=10)
  1. Callback function
xxxxxxxxxx
# Normal image transfer processing 
def topic(msg):
    if not isinstance(msg, Image):
        return
    bridge = CvBridge()
    frame = bridge.imgmsg_to_cv2(msg, "bgr8")
    frame = cv.resize(frame, (640, 480))
    frame = cv.flip(frame, 1)
    # opencv mat ->  ros msg
    msg = bridge.cv2_to_imgmsg(frame, "bgr8")
    pub_img.publish(msg)

# Compressed image transmission processing 
def compressed_topic(msg):
    if not isinstance(msg, CompressedImage): return
    bridge = CvBridge()
    frame = bridge.compressed_imgmsg_to_cv2(msg, "bgr8")
    frame = cv.resize(frame, (640, 480))
    frame = cv.flip(frame, 1)
    # Create CompressedIamge 
    msg = CompressedImage()
    msg.header.stamp = rospy.Time.now()
    msg.data = np.array(cv.imencode('.jpg', frame)[1]).tostring()
    pub_comimg.publish(msg)

3.3、Jetson CSI camera

3.3.1. Start Jetson CSI camera

xxxxxxxxxx
roslaunch yahboomcar_visual yahboom_csi.launch

View threads

xxxxxxxxxx
rostopic list 

You can see a lot of topics, just a few commonly used in this section

topic nametype of data
/usb_cam/image_rawsensor_msgs/Image
/usb_cam/image_raw/compressedsensor_msgs/Image

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

xxxxxxxxxx
rostopic echo /csi_cam_0/image_raw/encoding

image-20210903120844654

The topic with [compressed] or [compressedDepth] after the topic is a compressed topic. When ROS transmits images, data packets may be lost due to factors such as the network, the running speed of the host, the running memory of the host, and the huge amount of video stream data. off topic. So there is no way, I can only subscribe to the compressed topic. Open two images at the same time to subscribe to different topics for testing. If the device performance is good and the network is also good, there will be no change. Otherwise, you will find that the topics after image compression will be much smoother.

image-20210903140543123

3.2.2. Start the color map subscription node

xxxxxxxxxx
roslaunch yahboomcar_visual usb_cam_flip.launch 
  • In this case, you need to change usb_cam_flip_usb.py to usb_cam_flip.py

    image-20210903112012709

  • py code analysis

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

  1. Create subscribers

The subscribed topic is ["/csi_cam_0/image_raw"], the data type is [Image], and the callback function [topic()].

The topic of subscription is ["/csi_cam_0/image_raw/compressed"], data type [CompressedImage], and callback function [compressed_topic()].

  1. Create a publisher

The published topic is ["/csi_cam_0/image_flip"], data type [Image], queue size [10].

The posted topic is ["/csi_cam_0/image_flip/compressed"], data type [CompressedImage], queue size [10].

xxxxxxxxxx
sub_img = rospy.Subscriber("/csi_cam_0/image_raw", Image, topic)
pub_img = rospy.Publisher("/csi_cam_0/image_flip", Image, queue_size=10)
sub_comimg = rospy.Subscriber("/csi_cam_0/image_raw/compressed", CompressedImage, compressed_topic)
pub_comimg = rospy.Publisher("/csi_cam_0/image_flip/compressed", CompressedImage, queue_size=10)
  1. Callback function
xxxxxxxxxx
# Normal image transfer processing 
def topic(msg):
    if not isinstance(msg, Image):
        return
    bridge = CvBridge()
    frame = bridge.imgmsg_to_cv2(msg, "bgr8")
    frame = cv.resize(frame, (640, 480))
    frame = cv.flip(frame, 1)
    # opencv mat ->  ros msg
    msg = bridge.cv2_to_imgmsg(frame, "bgr8")
    pub_img.publish(msg)

# Compressed image transmission processing 
def compressed_topic(msg):
    if not isinstance(msg, CompressedImage): return
    bridge = CvBridge()
    frame = bridge.compressed_imgmsg_to_cv2(msg, "bgr8")
    frame = cv.resize(frame, (640, 480))
    frame = cv.flip(frame, 1)
    # Create CompressedIamge 
    msg = CompressedImage()
    msg.header.stamp = rospy.Time.now()
    msg.data = np.array(cv.imencode('.jpg', frame)[1]).tostring()
    pub_comimg.publish(msg)

 

AR QR code
ROS+Opencv application

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/中文