본문 바로가기

Python

Perspective transform

반응형

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

img = cv2.imread('D:/21_pycharm_project/Proj02/mark4.bmp')
rows,cols,ch = img.shape

# input potision
pts1 = np.float32([[98,21],[187,21],[96,102],[188,102]])


# output position
pts2 = np.float32([[128,21],[157,21],[96,102],[188,102]])

# get perspective transform matrix
M = cv2.getPerspectiveTransform(pts1,pts2)


# warp
dst = cv2.warpPerspective(img,M,(300,120))

plt.subplot(121),plt.imshow(img),plt.title('Input')
plt.subplot(122),plt.imshow(dst),plt.title('Output')
plt.show()

cv2.imwrite('D:/21_pycharm_project/Proj02/mark4_.bmp', dst)