计算单应矩阵,图像矫正,opencv的findHomography
通过一一对应的点,计算映射矩阵,进行变换
from PIL import Image
from pylab import *
import numpy as np
import cv2
if __name__ == '__main__':
im = array(Image.open('book.jpg'))
imshow(im)
src_point = ginput(4)
src_point = np.float32(src_point)
dsize=(600,1000)
dst_point = np.float32([[0,0],[0,dsize[1]-1],[dsize[0]-1,dsize[1]-1],[dsize[0]-1,0]])
h, s = cv2.findHomography(src_point, dst_point, cv2.RANSAC, 10)
book = cv2.warpPerspective(im, h, dsize)
book = cv2.cvtColor(book, cv2.COLOR_RGB2BGR)
cv2.imwrite('book_tran.jpg',book)