Image rotation

Image rotation refers to the process of rotating an image at a certain angle according to a certain position. The image still maintains its original size during rotation. After the image is rotated, the horizontal symmetry axis, vertical symmetry axis and center coordinate origin of the image may be transformed, so the coordinates in image rotation need to be converted accordingly. As shown below:

Assuming that the image is rotated counterclockwise by θ, the rotation transformation can be obtained according to the coordinate transformation as:

and

(2) By bringing in (1), we can get:

That is as follows:

The gray value of the rotated image is equal to the gray value of the corresponding position in the original image as follows:

f(x′,y′)=f(x,y)

The above is the principle of rotation, but the API provided by OpenCV can directly obtain the transformation matrix through functions. The syntax format of this function is:

matRotate = cv2.getRotationMatrix2D(center, angle, scale)

center: center point of rotation

angle: Angle of rotation. Positive numbers are counterclockwise; negative numbers are clockwise.

scale: transformation scale (zoom size). 1 means no change, less than 1 means shrinking, and greater than 1 means enlarging.

After entering the Raspberry Pi 5 desktop, open a terminal and run the following command to start the container corresponding to Dofbot:

Access Jupyter Lab within Docker:

Code path:/root/Dofbot/4.opencv/2.Transform/06_rotation.ipynb

The following will display the comparison between the original image and the rotated image in the jupyterLab control.