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.

21 lines
607 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 warpAffine(img_path, matSrc, matDst):
img = cv2.imread(img_path, 1)
height, width = img.shape[:2]
M = cv2.getAffineTransform(np.float32(matSrc), np.float32(matDst)) # 生成矩阵
result = cv2.warpAffine(img, M, (width, height))
cv2.imwrite('./output/warpAffine.jpg', result)
'''
输入一张图片旋转前三个点的坐标matSrc旋转后三个点的坐标matDst
输出:仿射变换后的图片
'''
if __name__ == '__main__':
warpAffine(sys.argv[1], eval(sys.argv[2]), eval(sys.argv[3]))