OpenCV中提供的函数
Geometric Image Transformations
官方文档2D变换1
- 避免采样误差:In fact, to avoid sampling artifacts, the mapping is done in the reverse order, from destination to the source. In case when you specify the forward mapping , the OpenCV functions first compute the corresponding inverse mapping and then use the above formula. 即给定src->dst转换矩阵,实际中也会先算reverse矩阵,再map。
- 原图不存在点的推测(因为即使reverse map,也可能再在原图是float)
- In the simplest case, the coordinates can be just rounded to the nearest integer coordinates and the corresponding pixel can be used. This is called a nearest-neighbor interpolation. 近邻方法
- However, a better result can be achieved by using more sophisticated interpolation methods , where a polynomial function. 多项式拟合,具体的方法可以在resize的interpolation参数查到。
getAffineTransform
- 输入两组三个点,计算仿射变换。
- 计算的放射矩阵是2*3矩阵,可以从变换公式中看出,dst的x和src的(x,y)均相关,y亦然。
- 对于点的要求:Given 3 points on one plane(共面很重要) and 3 matching points on another you can calculate affine transform between those planes.
getPerspectiveTransform
- 输入两组四个点,计算透视变换。
- 透视变换矩阵3*3.
getRotationMatrix2D
- 根据center,angle,scale获取对应的2*3矩阵。
- 上面的变换方法是给定src、dst计算变换矩阵,这个是设计变换矩阵。
warpAffine
- 获取了各种2*3的变换矩阵后(比如getAffineTransform、getRotationMatrix2D),用该函数作用于原图,得到变换后的图。
- non in-place
warpPerspective
- 同理,使用3*3的透视变换矩阵,得到变换后的图像。
Motion Analysis and Object Tracking
estimateRigidTransform
- Computes an optimal affine transformation between two 2D point sets. 注意还是2D平面。
- If you can’t get your points with absolute precision (which is normally the case when you get them from an image) then you need more than 3 pairs of points to reduce the error. 如果使用三个点,那么estimateRigidTransform的结果和getAffineTransform结果一致。
- fullAffine参数若为True,则无任何限制共6个自由度;反之则有限制,为5个自由度。
Camera Calibration and 3D Reconstruction
findHomography
- Finds a perspective transformation between two planes.
- This one is more advanced. Not only it can deal with errors in locations of points, but it can also deal with existence of the outliers. 由于estimateRigidTransform使用的是最小化均方误差(i.e 最小二乘值),那么如果有outlier则效果会很差。
- It can use RANSAC or LMeDs to test possible matches and eliminate those outliers.
- It works like(是相似,不是 就是) multiple iterations of estimateRigidTransform: find least square match for different sub-sets of points. If you know that no outliers are present then you can set the ‘method’ argument to 0, and it will work like estimateRigidTransform - by trying to minimize least square error created from match of all points.
其他参考文章2
Geometric Image Transformations: https://docs.opencv.org/2.4/modules/imgproc/doc/geometric_transformations.html?highlight=getaffinetransform ↩︎