You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

20 lines
496 B

3 years ago
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]))