1. 程式人生 > >python-opencv 投影變換

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()