用于旋转 (线性变换),平移 (向量加).缩放(线性变换),错切,反转。
原理:
# coding:utf-8
import cv2
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
img = cv2.imread("E:/picture/aa.jpg")
img = cv2.resize(img,(640,822))
(r, g, b)=cv2.split(img)
img=cv2.merge([b,g,r])
rows,cols,ch = img.shape
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()
用于将2D矩阵图像变换成3D的空间显示效果,全景拼接。
原理:
# coding:utf-8
import cv2
import numpy as np
import matplotlib.pyplot as plt
import numpy as np
from PIL import Image
img = cv2.imread("E:/picture/aa.jpg")
img = cv2.resize(img,(640,822))
(r, g, b)=cv2.split(img)
img=cv2.merge([b,g,r])
rows,cols,ch = img.shape
pts1 = np.float32([[100,200],[500,200],[100,500],[500,500]])
pts2 = np.float32([[0,0],[300,0],[0,300],[300,300]])
M = cv2.getPerspectiveTransform(pts1,pts2)
dst = cv2.warpPerspective(img,M,(300,300))
plt.subplot(121),plt.imshow(img),plt.title('Input')
plt.subplot(122),plt.imshow(dst),plt.title('Output')
plt.show()