透視變換(單應性?)能提供更大的靈活性,可是一個透視投影並非線性變換,所以所採用的映射矩陣是3*3,且控點變爲4個,其餘方面與仿射變換徹底相似,下面的例程是針對密集變換,稀疏圖像變換則採用cvPerspectiveTransform函數來處理。數組
------------------------------------------------------------------------------------------------函數
WarpPerspectiveui
對圖像進行透視變換spa
void cvWarpPerspective( const CvArr* src, CvArr* dst,const CvMat* map_matrix,.net
int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,指針
CvScalar fillval=cvScalarAll(0) );code
srcorm
輸入圖像.blog
dstip
輸出圖像.
map_matrix
3×3 變換矩陣
flags
插值方法和如下開關選項的組合:
· CV_WARP_FILL_OUTLIERS- 填充全部縮小圖像的象素。若是部分象素落在輸入圖像的邊界外,那麼它們的值設定爲 fillval.
· CV_WARP_INVERSE_MAP- 指定 matrix 是輸出圖像到輸入圖像的反變換,所以能夠直接用來作象素插值。不然, 函數從 map_matrix 獲得反變換。
fillval
用來填充邊界外面的值
函數 cvWarpPerspective 利用下面指定矩陣變換輸入圖像:
要變換稀疏矩陣,使用 cxcore 中的函數 cvTransform 。
-----------------------------
GetPerspectiveTransform
由四對點計算透射變換
CvMat* cvGetPerspectiveTransform( const CvPoint2D32f*src, const CvPoint2D32f* dst,
CvMat*map_matrix );
#define cvWarpPerspectiveQMatrixcvGetPerspectiveTransform
src
輸入圖像的四邊形頂點座標。
dst
輸出圖像的相應的四邊形頂點座標。
map_matrix
指向3×3輸出矩陣的指針。
函數cvGetPerspectiveTransform計算知足如下關係的透射變換矩陣:
這裏,dst(i)= (x'i,y'i),src(i)= (xi,yi),i = 0..3.
------------------------------------------------------------------------------------------------
/*code*/