import cv2
import matplotlib.pyplot as plt
import numpy as np
# 读取图像
img1 = cv2.imread("test1.jpg")
# plt.imshow(img1[:,:,::-1])
# plt.show()
# 图像平移
h,w = img1.shape[:2]
# 平移矩阵,y方向向下平移50,x方向向右平移100
M = np.float32([[1,0,100],[0,1,50]])
dst = cv2.warpAffine(img1,M,(w,h))
# 图像显示
fig,axes = plt.subplots(1,2,figsize=(10,8),dpi=100)
axes[0].imshow(img1[:,:,::-1])
axes[0].set_title("original")
axes[1].imshow(dst[:,:,::-1])
axes[1].set_title("after transform")
plt.show()
结果: