OpenCV:图像几何变换

图像几何变换

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

img = cv.imread('book.jpg')
rows,cols,ch = img.shape
pts1 = np.float32([[151,332],[882,272],[119,1368],[1242,1188]])
pts2 = np.float32([[0,0],[300,0],[0,300],[300,300]])
M = cv.getPerspectiveTransform(pts1,pts2)
dst = cv.warpPerspective(img,M,(300,300))
cv.drawMarker(img, (151,332), (255,0,0), markerType=2, markerSize = 20, thickness=4)
cv.drawMarker(img, (882,272), (255,0,0), markerType=2, markerSize = 20, thickness=4)
cv.drawMarker(img, (119,1368), (255,0,0), markerType=2, markerSize = 20, thickness=4)
cv.drawMarker(img, (1242,1188), (255,0,0), markerType=2, markerSize = 20, thickness=4)
plt.subplot(121),plt.imshow(img),plt.title('Input')
plt.subplot(122),plt.imshow(dst),plt.title('Output')
plt.show()

OpenCV:图像几何变换_第1张图片

你可能感兴趣的:(机器视觉,opencv,计算机视觉,图像处理)