单应性矩阵由配对的内点计算出来
u,v是原始图片左边,对应得到变换后的图片坐标x,y,其中
变换矩阵可以拆成4部分,表示线性变换,比如scaling,shearing和ratotion。用于平移,产生透视变换。
重写之前的变换公式可以得到:
OpenCV 代码实现是getPerspectiveTransform()和findHomography()
/* Calculates coefficients of perspectivetransformation
*which maps (xi,yi) to (ui,vi), (i=1,2,3,4):
*
* c00*xi + c01*yi + c02
* ui= ---------------------
* c20*xi + c21*yi + c22
*
* c10*xi + c11*yi + c12
* vi= ---------------------
* c20*xi + c21*yi + c22
*
*Coefficients are calculated by solving linear system:
* /x0 y0 1 0 0 0 -x0*u0 -y0*u0 \ /c00\ /u0\
* |x1 y1 1 0 0 0 -x1*u1 -y1*u1 | |c01| |u1|
* |x2 y2 1 0 0 0 -x2*u2 -y2*u2 | |c02| |u2|
* |x3 y3 1 0 0 0 -x3*u3 -y3*u3 |.|c10|=|u3|,
*| 0 0 0 x0 y0 1 -x0*v0 -y0*v0 | |c11| |v0|
*| 0 0 0 x1 y1 1 -x1*v1 -y1*v1 | |c12| |v1|
*| 0 0 0 x2 y2 1 -x2*v2 -y2*v2 | |c20| |v2|
*\ 0 0 0 x3 y3 1 -x3*v3 -y3*v3 / \c21/ \v3/
*
*where:
* cij- matrix coefficients, c22 = 1
*/
cv::Mat cv::getPerspectiveTransform( constPoint2f src[], const Point2f dst[] )
{
}
更完善的函数是findHomography()
pairwise_matches_ contains the matching relation. BestOf2NearestMatcher.BestOf2NearestMatcher::match() which is derived from FeaturesMatcher which hasone operator(), the () below will invoke BestOf2NearestMatcher::match() whichwill calculate H matrix. 单应性矩阵计算从匹配的内点
matches_info.H = findHomography(src_points,dst_points, matches_info.inliers_mask, RANSAC);
都用于计算单应矩阵,即解一个线性方程组。由于单应矩阵有8个未知数(3*3,其中第9个数为1),所以至少需要4个点(每个点-x,y,提供2个约束方程)。
发现getPerspectiveTra