python-opencv 投影变换

#coding=utf-8
'''对于投影变换需要有4组坐标值'''
import cv2
import numpy as np
img = cv2.imread('timg.jpeg', cv2.CV_LOAD_IMAGE_GRAYSCALE)
h, w = img.shape[:2]
src=np.array([[0,0],[w-1,0],[0,h-1],[w-1,h-1]],np.float32)
dst=np.array([[50,50],[w/3,50],[50,h-1],[w-1,h-1]],np.float32)
P=cv2.getPerspectiveTransform(src,dst)#计算投影矩阵
r=cv2.warpPerspective(img,P,(w,h),borderValue=125)
cv2.imshow('img',img)
cv2.imshow('warpPerspective',r)
cv2.waitKey(0)
cv2.destroyAllWindows()

你可能感兴趣的:(Python)