yahboom
HomeLearn
Solution
Blog
Online Store
About Us
EN/中文
RDK X3 Robot📖
01. About RDK-X3-Robot
1. Instructions
  • 1. Introduction
  • 2. FAQ
  • 3. Battery and charger use precautions
  • 4.TF card expand capacity
2. Common problem analysis
02. Assembly video
  • Part1-Install Motor
  • Part2-Install Battert Fixing Column
  • Part3-Install Motor Coupling
  • Part4-Install Mecanum wheel
  • Part5-Install Expansion Board
  • Part6-Wiring Show
  • Part7-Install Main Control Board
  • Part8-Install Car Top Plate and Antenna
  • Part9-Install OLED Screen
  • Part10-Install Depth Camera(Optional)
  • Part11-Install OLED Screen
  • Part12-Install HD Camera
  • Part13-Install Top Plate
  • Part14-Install Right Side Plate
  • Part15-Motor Wiring Show
  • Part16-lnstall Car Body
  • Part17-Install Battery
  • Part18-Install Lidar
03. Remote control tutorial
  • 1. The phone APP remote tutorial
  • 2. USB wireless controller remote tutorial
04. ROS functional tutorial
  • 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 tutorial
  • 1. Update the firmware of the expansion module
  • 2. Install the Python driver library
  • 3. Set the type of bottom car
  • 4. Open and close the APP program control
  • 5. Turn hotspot mode on and off
  • 6. The buzzer blows
  • 7. Control the motor forward and reverse
  • 8. Control robot movement
  • 9. OLED display
  • 10. Control fan and lamp effect
06. Development environment setup
  • 1. Virtual Machine
  • 2. Linux Basics
  • 3. Remote connection
  • 4. Multi-computer communication configuration
  • 5. Bind the 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
  • 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 courses
  • 1. Introduction and use of lidar
  • 2. Lidar obstacle avoidance
  • 3. Lidar following
  • 4. Lidar guard
  • 5. Patrol
  • 6. gmapping algorithm
  • 7. cartographer algorithm
  • 8. Navigation and obstacle avoidance
  • 9. App mapping and navigation
10. OpenCV courses
  • 1. Introduction to OpenCV
  • 2. OpenCV geometric transformation
  • 3. OpenCV image processing
  • 4. OpenCV image beautification
  • 5. Qr code creation and identification
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 command
  • 7. Face detection
  • 8. Object detection
  • 9. Visual Inspection -OpenCV
  • 10. Visual inspection - Deep learning
  • 11. Human tracking
  • 12. Gesture control
12. Depth Camera courses
  • 1. Use depth camera
  • 2. Calibration of camera internal reference
  • 3. ROS+OpenCV Foundation
  • 4. AR vision
  • 5. Color tracking
  • 6. Object tracking
13. Multi vehicle control
  • 1. Multi-vehicle synchronous control
  • 2. Multi-vehicle navigation
Remote login control
  • 1. VNC and SSH remote login
  • 2. Jupyter lab login and case code running
Download
  • RemoteCtrl_APP(iOS/Android))
  • Mapping_APP(iOS_Android)
  • Code
  • System File
  • VM_File
  • Manual
  • Software_File
  • Hardware_File
  • ROS2_Basic_VM
Download ZIP

Welcome to RDK X3 Robot repository

3. OpenCV image processing

3. OpenCV image processing

3. OpenCV image processing3.1. Image grayscale3.2. Image binarization3.3. Image edge detection3.4. Line Segment drawing3.5. Draw Rectangles3.6. Draw the circle3.7. Draw the ellipse3.8. Draw polygons3.9. Draw text

Before running the sample program, you need to switch to the directory where the code is located. SSH connects the car, runs at the terminal,

xxxxxxxxxx
cd /userdata/yahboomcar_ws/src/yahboomcar_astra/opencv_examples

3.1. Image grayscale

Gray-scale processing is the process of transforming a color image into a gray-scale image. Color image is divided into R, G, B three components, respectively, showing a variety of colors such as red, green and blue, grayscale is the process of making the color R, G, B components equal. Pixels with large gray values are brighter (the maximum pixel value is 255, which is white), and darker (the lowest pixel is 0, which is black). The core idea of image grayscale is R = G = B, which is also called grayscale value.

1) Maximum method: the value of R, G, B after conversion is equal to the largest one of the three values before conversion, that is: R=G=B=max (R, G, B). The brightness of the gray image converted by this method is very high.

2) Average value method: the value of R,G,B after conversion is the average value of R,G,B before conversion. That is, R=G=B=(R+G+B)/3. The gray image produced by this method is relatively soft.

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_1.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # 图像灰度化# Image grayscale
    cv2.imwrite('figures/3_1.jpg', gray)

The resulting image is shown here,

1685006656772

3.2. Image binarization

The core idea of binarization is to set a threshold, greater than the threshold is 0 (black) or 255 (white), so that the image is called black and white. The threshold can be fixed or adaptive. The adaptive threshold is generally the comparison of a point pixel with the average value of a region's pixels or a weighted sum of Gaussian distributions, where a difference can be set or no difference can be set.

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_2.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # 先进行灰度化处理# Grayscale processing first
    ret, binary = cv2.threshold(gray,180,255,cv2.THRESH_BINARY_INV) 
    cv2.imwrite('figures/3_2.jpg', binary)
​
'''
图像二值化:ret,binary = cv2.threshold(src,thresh,maxVal,thresholdType)
    参数:
        src:原图像
        thresh:当前阈值
        maxVal:最大阈值,一般为255
        thresholdType:阈值类型,一般有下面几个值,
            THRESH_BINARY=0:大于阈值的灰度值为maxVal,小于阈值的为0。
            THRESH_BINARY_INV=1:大于阈值的灰度值为0,小于阈值的为maxVal。
            THRESH_TRUNC=2:大于阈值的灰度值为该阈值,小于阈值的不变。
            THRESH_TOZERO=3:小于阈值的灰度值为0,大于阈值的不变。
            THRESH_TOZERO_INV=4:大于阈值的灰度值为0,小于阈值的不变。
    返回值:
        ret:与参数thresh一致
        binary:结果图像
Image binarization: ret, binary = cv2. Threshold (SRC, thresh, very much, thresholdType)
    Parameters:
        src: indicates the original image
        thresh: indicates the current threshold
        maxVal: indicates the maximum threshold, usually 255
        thresholdType: indicates the threshold type, which generally has the following values.
            THRESH_BINARY=0: The gray value larger than the threshold is maxVal, and the gray value smaller than the threshold is 0.
            THRESH_BINARY_INV=1: The gray value larger than the threshold is 0, and the gray value smaller than the threshold is maxVal.
            THRESH_TRUNC=2: The gray value that is larger than the threshold is the threshold, and the gray value that is smaller than the threshold is unchanged.
            THRESH_TOZERO=3: The gray value less than the threshold is 0, and the gray value greater than the threshold is unchanged.
            THRESH_TOZERO_INV=4: The gray value     larger than the threshold is 0, and the gray value smaller than the threshold is unchanged.
    Return value:
        ret: This parameter is consistent with thresh
        binary: Result image
'''

The resulting image is shown here,

1685006697718

3.3. Image edge detection

Image edge detection can significantly reduce the data size of the image while retaining the original image attributes. Among the commonly used edge detection methods, Canny edge detection algorithm is one of the methods with strict definition and can provide good and reliable detection. Because it satisfies the three standards of edge detection and has the advantages of simple implementation process, it has become one of the most popular algorithms for edge detection.

Canny edge detection algorithm can be divided into the following 5 steps:

  • Use Gaussian filters to smooth the image and filter out noise
  • Calculate the gradient intensity and direction of each pixel in the image
  • Apply Non-Maximum Suppression suppression to eliminate spurious responses from edge detection Double-Threshold detection is applied to determine real and potential edges
  • Edge detection is finally completed by suppressing isolated weak edges

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_3.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY) # 图像灰度化# Image grayscale
    imgG = cv2.GaussianBlur(gray,(3,3),0)
    dst = cv2.Canny(imgG,50,50)
    cv2.imwrite('figures/3_3.jpg', dst)
​
'''
高斯过滤(减噪处理):cv2.GaussianBlur(src,ksize,sigmaX[,dst[,sigmaY[,borderType]]])-> dst
    src:输入的图像,一般是灰度后的图片
    ksize:高斯内核大小
    sigmaX:X方向上的高斯核标准偏差
    sigmaY:Y方向上的高斯核标准差
    dst:处理后的图像
Canny边缘检测:edges=cv2.Canny(image,threshold1,threshold2[,apertureSize[,L2gradient]])
    edges:计算得到的边缘图像
    image:计算得到的边缘图像,一般是高斯处理后得到的图像
    threshold1:处理过程中的第一个阈值
    threshold2:处理过程中的第二个阈值
    apertureSize:Sobel 算子的孔径大小
    L2gradient:默认值为False,使用L1范数计算;若为True则使用L2范数
 Gaussian filter (noise reduction processing) : 
cv2.GaussianBlur(src,ksize,sigmaX[,dst[,sigmaY[,borderType]]]) -> dst.
    src: The input image, usually a grayscale image
    ksize: indicates the size of a Gaussian kernel
    sigmaX: Gaussian kernel standard deviation in the X direction
    sigmaY: standard deviation of Gaussian kernel in the Y direction
    dst: processed image
Canny edge detection: 
edges = cv2. Canny (image, threshold1 and threshold2 [, apertureSize [, L2gradient]])
    edges: Calculated edge images
    image: The computed edge image, which is generally the image obtained after Gaussian processing
    threshold1: indicates the first threshold during processing
    threshold2: The second threshold during processing
    apertureSize: indicates the aperture size of the Sobel operator
    L2gradient: The default value is False and is calculated using L1 norm. If True, the L2 norm is used
'''

The resulting image is shown here,

1685006729232

3.4. Line Segment drawing

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_4.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    line = cv2.line(img, (50,20), (20,100), (255,0,255), 10)
    cv2.imwrite('figures/3_4.jpg', line)
​
'''
线段绘制:cv2.line(img,pt1,pt2,color,thickness=None,lineType=None,shift=None)
    img:画布或者载体图像
    pt1,pt2:必选参数。线段的坐标点,分别表示起始点和终止点
    color:必选参数。用于设置线段的颜色
    thickness:可选参数。用于设置线段的宽度
    lineType:可选参数。用于设置线段的类型,类型如下,
        8:8邻接连接线(默认)
        4:4邻接连接线
        cv2.LINE_AA:抗锯齿
Line drawing: 
cv2. Line (img, pt1 and pt2, color, thickness = None, lineType = None, shift = None)
    img: canvas or carrier image
    pt1,pt2: This parameter is mandatory. The coordinate point of a line segment, representing the starting point and the ending point respectively
    color:This parameter is mandatory. Used to set the color of the line segment
    thickness: It is optional. Used to set the width of the line segment
    lineType: This parameter is optional. Used to set the type of the line segment, the type is as follows,
        8:8 Adjacent Cable (default)
        4:4 Connect the adjacent cable
        cv2.LINE_AA: anti-aliasing
'''

The resulting image is shown here,

1685006812102

3.5. Draw Rectangles

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_5.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    rect = cv2.rectangle(img, (50,20), (100,100), (255,0,255), 10)
    cv2.imwrite('figures/3_5.jpg', rect)
​
'''
绘制矩形:cv2.rectangle(img,pt1,pt2,color,thickness=None,lineType=None,shift=None)
    img:画布或者载体图像
    pt1,pt2:必选参数。分别表示矩形的左上角和右下角顶点,从而确定唯一的矩形
    color:必选参数。用于设置矩形的颜色
    thickness:可选参数。用于设置矩形边的宽度,当值为负数时,表示对矩形进行填充
    lineType:可选参数。用于设置线段的类型,类型如下,
        8:8邻接连接线(默认)
        4:4邻接连接线
        cv2.LINE_AA:抗锯齿
        cv2.FILLED:填充
Draw a rectangle:
cv2. A rectangle (img, pt1 and pt2, color, thickness = None, lineType = None, shift = None)
    img: canvas or carrier image
    pt1,pt2: This parameter is mandatory. Represent the top left and bottom right vertices of the rectangle respectively, thus determining the unique rectangle
    color:This parameter is mandatory. Used to set the color of the rectangle
    thickness: It is optional. Used to set the width of the side of a rectangle. When the value is negative, the rectangle is filled
    lineType: This parameter is optional. Used to set the type of the line segment, the type is as follows,
        8:8 Adjacent Cable (default)
        4:4 Connect the adjacent cable
        cv2.LINE_AA: anti-aliasing
        cv2.FILLED: indicates that the space is filled
'''

The resulting image is shown here,

1685006872474

3.6. Draw the circle

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_6.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    circle = cv2.circle(img, (80,80), 50, (255,0,255), 10)
    cv2.imwrite('figures/3_6.jpg', circle)
​
'''
绘制圆形:cv2.circle(img, center, radius, color[,thickness[,lineType]])
    img:画布或者载体图像
    center:必选参数。圆心坐标,格式为(X坐标值,Y坐标值)
    radius:必选参数。圆的半径
    thickness:可选参数。用于设置圆形轮廓的粗细,当值为负数时,表示对圆进行填充
    lineType:可选参数。用于设置线段的类型,类型如下,
        8:8邻接连接线(默认)
        4:4邻接连接线
        cv2.LINE_AA:抗锯齿
        cv2.FILLED:填充
Draw a circle: cv2.circle(img, center, radius, color[,thickness[,lineType]])
    img: canvas or carrier image
    center: This parameter is mandatory. Center coordinates, in the format of (X coordinates, Y coordinates)
    radius: This parameter is mandatory. Radius of a circle
    thickness: It is optional. Used to set the thickness of the circle outline. When the value is negative, it indicates that the circle is filled
    lineType: This parameter is optional. Used to set the type of the line segment, the type is as follows,
        8:8 Adjacent Cable (default)
        4:4 Connect the adjacent cable
        cv2.LINE_AA: anti-aliasing
        cv2.FILLED: indicates that the space is filled
'''

The resulting image is shown here,

1685007033215

3.7. Draw the ellipse

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_7.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    ellipse = cv2.ellipse(img, (80,80), (20,50),0,0, 360,(255,0,255), 5)
    cv2.imwrite('figures/3_7.jpg', ellipse)
​
'''
绘制椭圆:cv2.ellipse(img,center,axes,angle,StartAngle,endAngle,color[,thickness[,lineType])
    center:椭圆的中心点,(x,y)
    axes:指的是短半径和长半径,(x,y)
    StartAngle:圆弧起始角的角度
    endAngle:圆弧终结角的角度
    img、color、thickness、lineType可以参考圆的说明
Draw the ellipse :cv2.ellipse (img, center, axes, Angle, StartAngle, endAngle, color [, thickness, lineType [])
    center: The center point of the ellipse, (x, y)
    axes: refers to short radius and long radius, (x, y)
    StartAngle: indicates the start Angle of an arc
    endAngle: indicates the endAngle of the arc
    img, color, thickness, lineType refer to the circle description
'''

The resulting image is shown here,

1685007360141

3.8. Draw polygons

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_8.py
xxxxxxxxxx
import cv2
import numpy as np
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    points = np.array([[120,50], [40,140], [120,70], [110,110], [50,50]], np.int32)
    polylines = cv2.polylines(img, [points],True,(255,0,255), 5)
    cv2.imwrite('figures/3_8.jpg', polylines)
​
'''
绘制多边形:cv2.polylines(img,[pts],isClosed,color[,thickness[,lineType]])
    pts:多边形的顶点
    isClosed:是否闭合(True/False)
    其他参数参照圆的绘制参数
Draw polygons: cv2.polylines(img,[pts],isClosed,color[,thickness[,lineType]])
    pts: vertex of a polygon
    isClosed: Indicates whether it is closed (True/False).
    Refer to the drawing parameters of the circle for other parameters
'''

The resulting image is shown here,

1685007398443

3.9. Draw text

After the car terminal switches to the directory where the code is located, run the program,

xxxxxxxxxx
python3 3_9.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
    img = cv2.imread('figures/yahboom.jpg')
    cv2.putText(img,'This is Yahboom!',(50,50),cv2.FONT_HERSHEY_SIMPLEX,1,(0,200,0),2)
    cv2.imwrite('figures/3_9.jpg', img)
​
'''
绘制文字:cv2.putText(img,str,origin,font,size,color,thickness)
    img:输入图像
    str:绘制的文字
    origin:左上角坐标(整数),可以理解成文字是从哪里开始的
    font:字体
    size:字体大小
    color:字体颜色
    thickness:字体粗细
Draw text: cv2.putText(img,str,origin,font,size,color,thickness)    img: Input the image
    str: Drawn text
    origin: Top-left coordinates (integers), which can be understood as where did the text start
    font: Font
    size: font size
    color: indicates the font color
    thickness: type thickness
'''

The resulting image is shown here,

1685007435120

 

OpenCV geometric transformation
OpenCV image beautification

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