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