1. The affine matrix computing
1) Equation Method:
cv2.getAffineTransform (src, dst), src and dst represent the coordinates and the coordinate transformation of the original, two-dimensional and three rows are ndarray 2 columns.
1 import cv2 2 import numpy as np 3 src = np.array([[0,0],[200,0],[0,200]],np.float32) 4 dst = np.array([[0,0],[100, 0], [0,100]], np.float32) 5 A = cv2.getAffineTransform(src, dst) 6 print(A) 7 #array([[0.5, 0. , 0. ], 8 # [0. , 0.5, 0. ]])
2) matrix:
cv2.getRotationMatrix2D (center, angle, scale), center to center point coordinate transformation, scale is a scaling factor, angle of rotation is a counterclockwise angle (angle in radians, non radians).
1 import numpy as np 2 import cv2 3 A = cv2.getRotationMatrix2D((40, 50), 30, 0.5) 4 print(A.dtype) 5 #dtype('float64') 6 print(A) 7 #[[ 0.4330127 0.25 10.17949192] 8 # [-0.25 0.4330127 38.34936491]]