# 图像平移
image1='C:\\Users\\10107472\\Desktop\\myfile\\tensorflow-yolov\\read.jpg'
img = cv.imread(image1,0)
rows,cols = img.shape
print('image_original=',img.shape)
M = np.float32([[1,0,100],[0,1,50]]) # 平移矩阵
dst = cv.warpAffine(img,M,(300,420)) # img为需要变换的图像,M为需要平移的位置,(300,420)为平移后图像尺寸
print('dst.shape=',dst.shape)
cv.imshow('original img',img)
cv.imshow('change img',dst)
cv.waitKey(0)
cv.destroyAllWindows()