This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.
import sys
import cv2
import numpy as np
import matplotlib.pyplot as plt
def translate(img_path, x, y):
img = cv2.imread(img_path, 1)
M = np.float32([[1, 0, x], [0, 1, y]])
result = cv2.warpAffine(img, M, (img.shape[1], img.shape[0]))
cv2.imwrite('./output/translate.jpg', result)
'''
输入:一张图片,x方向移动数值,y方向移动数值
输出:平移后的图片
if __name__ == '__main__':
translate(sys.argv[1], eval(sys.argv[2]), eval(sys.argv[3]))