图片的透视变换perspective transform——旋转矫正
简介
一幅倾斜了的图片如何进行矫正,这也许比较有用,比如,传统的车牌中有将倾斜了的车牌文字,用 Radon变换进行矫正。如果我们知道了四个点的坐标,是否也可以进行矫正处理?
代码
Created on 2017年8月20日 @author: XT # import the necessary packages import matplotlib.pyplot as plt import imutils from imutils import perspective import numpy as np import cv2 # load the notecard code image, clone it, and initialize the 4 points # that correspond to the 4 corners of the notecard notecard = cv2.imread("../image/notecard.png") clone = notecard.copy() pts = np.array([(73, 239), (356, 117), (475, 265), (187, 443)]) # loop over the points and draw them on the cloned image for (x, y) in pts: cv2.circle(clone, (x, y), 5, (0, 255, 0), -1) # apply the four point tranform to obtain a "birds eye view" of # the notecard warped = perspective.four_point_transform(notecard, pts) # show the original and warped images cv2.imshow("Original", clone) cv2.imshow("Warped", warped) plt.figure("Original opencv2matplotlib") plt.imshow(imutils.opencv2matplotlib(clone)) plt.show() cv2.waitKey(0)