Welcome to Raspberry Pi 4B repository
5.Affine Map
Affine Map
Affine Transformation(Affine Map) is a linear transformation from two-dimensional coordinates (x, y) to two-dimensional coordinates (u, v).
Its mathematical expression is as follows,
The corresponding homogeneous coordinate matrix mathematical expression is as follow, 
The affine transformation maintains the "straightness" of the two-dimensional graphics and "parallelism".
Straightness: The straight line will keep a straight line after affine transformation.
Parallelism: After the affine transformation, the parallel line will keep parallel line, and the position order of all points on the straight line will not be changed, and the relative positional relationship between the two straight lines will not be changed.
Non-collinear three pairs of corresponding points can determine an affine transformation.
Affine transformation = picture rotation + picture lift.
Affine transformation also requires an M matrix. Due to the complexity of the affine transformation, it is difficult to find this matrix. OpenCV can automatically solve the matrix M according to the correspondence between the three points before and after the transformation.
M = cv2.getAffineTransform (pos1, pos2), pos1 and pos2 are the corresponding positional relationship before and after the transformation.
The output is the affine matrix M.
Then, we can use the function cv2.warpAffine ().
Two methods of image transformation cv2.warpAffine and cv2.warpPerspective
Code:
|
|
After running the above program, we can see the picture shown below.

[Orginial picture] [Affine Transformation picture]