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

2. OpenCV geometric transformation

OpenCV Geometric Transformation

OpenCV Geometric Transformation2.1, Image scaling2.2, Image cropping2.3, Image translation2.4, Image Mirroring

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

xxxxxxxxxx
cd /home/sunrise/yahboomcar_ws/src/yahboomcar_astra/opencv_examples

2.1, Image scaling

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

xxxxxxxxxx
python3 2_1.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
img = cv2.imread('figures/yahboom.jpg')
print(img.shape)
x, y = img.shape[0:2]
img_resize = cv2.resize(img, (int(y / 2), int(x / 2)))
cv2.imwrite('figures/2_1.jpg', img_resize)
print(img_resize.shape)

'''
Image scaling: cv2.resize(InputArray src,OutputArray dst,Size,fx,fy,interpolation)
InputArray src: input image
OutputArray ds: output image
Size: output image size
fx,fy: scaling factors along the x-axis and y-axis
interpolation: interpolation method, with the following options,
INTER_NEAREST (nearest neighbor interpolation)
INTER_LINEAR (bilinear interpolation, default setting)
INTER_AREA (resample using pixel area relationship)
INTER_CUBIC (bicubic interpolation of 4x4 pixel neighborhood)
INTER_LANCZOS4 (Lanczos interpolation of 8x8 pixel neighborhood)
'''

The terminal outputs the size of the original image and the reduced image (representing the width, height and number of channels of the image respectively),

1685002333845

You can also see the difference in size when you open the image,

1685002275425

2.2, Image cropping

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

xxxxxxxxxx
python3 2_2.py
xxxxxxxxxx
import cv2
if __name__ == '__main__':
img = cv2.imread('figures/yahboom.jpg')
dst = img[0:100,100:200] # Select area X: 0-100 Y: 100-200, cannot exceed the original image resolution
cv2.imwrite('figures/2_2.jpg', dst)

The final image is as shown in the figure,

1685003397012

2.3, Image translation

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

xxxxxxxxxx
python3 2_3.py
xxxxxxxxxx
import cv2
import numpy as np
if __name__ == '__main__':
img = cv2.imread('figures/yahboom.jpg')
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
matShift = np.float32([[1,0,100],[0,1,50]]) # 2*3
dst = cv2.warpAffine(img, matShift, (width,height))
cv2.imwrite('figures/2_3.jpg', dst)

'''
Image translation: cv2.warpAffine(src,M,dsize[,dst[,flags[,borderMode[,borderValue]]]])
src: input image
M: affine transformation matrix, generally reflects the relationship of translation or rotation (InputArray type)
dsize: output image size
flags: combination of interpolation methods (int type)
borderMode: border pixel mode (int type)
borderValue: (important!) border filling value; by default, it is 0
Generally, only the first three parameters can be set to achieve basic affine transformation effects.
'''

The final image is as shown in the figure,

1685003830986

How to get the transformation matrix M? The following is an example to illustrate,

The original image src is converted to the target image dst through the conversion matrix M:

dst(x, y) = src(M11x + M12y+M13, M21x+M22y+M23)

Move the original image src to the right by 100 pixels and move it down by 50 pixels, then the corresponding relationship is:

dst(x, y) = src(x+100, y+50)

Complete the above expression, that is:

dst(x, y) = src(1·x + 0·y + 100, 0·x + 1·y + 50)

According to the above expression, the values of each element in the corresponding conversion matrix M can be determined as:

M11=1, M12=0, M13=100, M21=0, M22=1, M23=50.

Substitute the above values into the transformation matrix M, and we get:

M = [[1,0,100],[0,1,50]]

2.4, Image Mirroring

There are two types of image mirroring: horizontal mirroring and vertical mirroring. Horizontal mirroring uses the vertical center line of the image as the axis to swap the pixels of the image, that is, swap the left and right halves of the image. Vertical mirroring uses the horizontal center line of the image as the axis to swap the upper and lower halves of the image.

Transformation principle:

Let the width of the image be width and the length be height. (x, y) are the transformed coordinates, (x0, y0) are the coordinates of the original image,

  • Horizontal mirror transformation

Forward mapping: x=width-x0-1, y=y0

Backward mapping: x0=width-x-1, y0=y

  • Vertical mirror transformation

Upward mapping: x=x0, y=height-y0-1

Downward mapping: x0=x, y0=height-y-1

Summary: In horizontal mirror transformation, the entire image is traversed, and then each pixel is processed according to the mapping relationship. In fact, horizontal mirror transformation is to swap the image coordinate columns to the right and the right columns to the left, and the transformation can be done in columns. The same is true for vertical mirror transformation, which can be transformed in rows.

Take vertical transformation as an example. After switching the terminal to the directory where the code is located, run the program.

xxxxxxxxxx
python3 2_4.py
xxxxxxxxxx
import cv2
import numpy as np
if __name__ == '__main__':
img = cv2.imread('figures/yahboom.jpg')
imgInfo = img.shape
height = imgInfo[0]
width = imgInfo[1]
deep = imgInfo[2]
newImgInfo = (height*2,width,deep)
dst = np.zeros(newImgInfo,np.uint8)#uint8
for i in range(0,height):
for j in range(0,width):
dst[i,j] = img[i,j]
dst[height*2-i-1,j] = img[i,j]
cv2.imwrite('figures/2_4.jpg', dst)

The final image is as shown in the figure,

1685004046699

Getting started with OpenCV
OpenCV Image Processing

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