opencv透视变换GetPerspectiveTransform的总结

时间:2023-03-09 05:53:02
opencv透视变换GetPerspectiveTransform的总结

对于透视变换,必须为map_matrix分配一个3x3数组,除了3x3矩阵和三个控点变为四个控点外,透视变化在其他方面与仿射变换完全类似。具体可以参考:点击打开链接

主要用到两个函数WarpPerspective和GetPerspectiveTransform。

1)WarpPerspective

对图像进行透视变换

void cvWarpPerspective( const CvArr* src, CvArr* dst,const CvMat* map_matrix,

int flags=CV_INTER_LINEAR+CV_WARP_FILL_OUTLIERS,

CvScalar fillval=cvScalarAll(0) );

src

输入图像.

dst

输出图像.

map_matrix

3×3 变换矩阵

flags

插值方法和以下开关选项的组合:

·       CV_WARP_FILL_OUTLIERS- 填充所有缩小图像的象素。如果部分象素落在输入图像的边界外,那么它们的值设定为 fillval.

·       CV_WARP_INVERSE_MAP- 指定 matrix 是输出图像到输入图像的反变换,因此可以直接用来做象素插值。否则, 函数从 map_matrix 得到反变换。

fillval

用来填充边界外面的值

函数 cvWarpPerspective 利用下面指定矩阵变换输入图像:opencv透视变换GetPerspectiveTransform的总结

  • 如果没有指定 CV_WARP_INVERSE_MAP , opencv透视变换GetPerspectiveTransform的总结
  • 否则, opencv透视变换GetPerspectiveTransform的总结

要变换稀疏矩阵,使用 cxcore 中的函数 cvTransform 。

2)GetPerspectiveTransform

由四对点计算透射变换

CvMat* cvGetPerspectiveTransform( const CvPoint2D32f*src, const CvPoint2D32f* dst,

CvMat*map_matrix );

#define cvWarpPerspectiveQMatrixcvGetPerspectiveTransform

src

输入图像的四边形顶点坐标。

dst

输出图像的相应的四边形顶点坐标。

map_matrix

指向3×3输出矩阵的指针。

函数cvGetPerspectiveTransform计算满足以下关系的透射变换矩阵:

opencv透视变换GetPerspectiveTransform的总结

这里,dst(i)= (x'i,y'i),src(i)= (xi,yi),i = 0..3.