import cv2 as cv import numpy as np import matplotlib.pyplot as plt img = cv.imread("../SampleImages/pomeranian.png", cv.IMREAD_COLOR) rows,cols = img.shape[:2] print(img.shape[:2]) #使用getAffineTransform来获得仿射变换的矩阵M #cv.getAffineTransform(pts 1,pts 2) #pts 1: 原图中的3个点坐标 #pts 2:经过放射变换后的3个点坐标 #参考资料:https://blog.csdn.net/weixin_45335726/article/details/122531876 pts1 = np.float32([[50,50],[200,50],[50,200]]) pts2 = np.float32([[100,100],[200,50],[100,250]]) M = cv.getAffineTransform(pts1,pts2) img_affine_transform = cv.warpAffine(img, M, (cols,rows)) #显示图像 fig,axes = plt.subplots(nrows=1,ncols=2,figsize=(10,8),dpi=100) axes[0].imshow(img[:,:,::-1]) axes[0].set_title("Original") axes[1].imshow(img_affine_transform[:,:,::-1]) axes[1].set_title("Affine Transformed")