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

This file contains ambiguous Unicode characters!

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]))