Python 9. OpenCV 仿射变换

import cv2
import numpy as np
from matplotlib import pyplot as plt

img = cv2.imread('pic3.PNG')

cv2.imshow('img', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

rows, cols = img.shape[:2]
pts1 = np.float32([[50, 50], [200, 50], [50, 200]])
pts2 = np.float32([[10, 100], [200, 50], [100, 250]])

M = cv2.getAffineTransform(pts1, pts2)
dst = cv2.warpAffine(img, M, (cols, rows))

plt.subplot(121), plt.imshow(img), plt.title('Input')
plt.subplot(122), plt.imshow(dst), plt.title('Output')
plt.show()
发布了54 篇原创文章 · 获赞 41 · 访问量 7901

猜你喜欢

转载自blog.csdn.net/qq_36071362/article/details/104110313