答:使用perspectiveTransform()。
findHomography 函数是求两幅图像的单应性矩阵,它是一个3*3的矩阵,但这里的单应性矩阵和3D重建中的单应性矩阵(透视矩阵3*4)是不一样的。之前一直混淆了两者的区别。
这里求两幅图像的单应性矩阵,只是利用多元方程组初步求解出H矩阵,然后利用迭代最小化反投影误差的方式进一步精确计算出H。H=(h11,h12,h13; h21,h22,h23; h31,h32,h33)
C++:
Mat
findHomography
(
InputArray
srcPoints
, InputArray
dstPoints
, int
method
=0, double
ransacReprojThreshold
=3, OutputArray
mask
=noArray()
) ?
Parameters:
srcPoints – Coordinates of the points in the original plane, a matrix of the type CV_32FC2 orvector .
dstPoints – Coordinates of the points in the target plane, a matrix of the type CV_32FC2 or avector .
method –
Method used to computed a homography matrix. The following methods are possible:
0 - a regular method using all the points
CV_RANSAC - RANSAC-based robust method
CV_LMEDS - Least-Median robust method
ransacReprojThreshold –
Maximum allowed reprojection error to treat a point pair as an inlier (used in the RANSAC method only). That is, if
then the point is considered an outlier. If srcPoints and dstPoints are measured in pixels, it usually makes sense to set this parameter somewhere in the range of 1 to 10.
mask – Optional output mask set by a robust method ( CV_RANSAC or CV_LMEDS ). Note that the input mask values are ignored.
代码移植,菜鸟请教:
1.此函数具体是怎样求解方程的呢?单应性矩阵有8个独立元素:H = h00 h01 h02 手动计算前两行元素与函数输出结
h10 h11 h12
h20 h21 1
果接近,但h20和h21只能得到比例且比例与所选点坐标有关,感觉解不唯一,请问大神可以告知这两个元素是怎样确定的吗?
2.找不到cvFindHomography()源码,能告诉从哪里能获得吗?或者直接发给我就更好啦!谢!
最近学习有关findhomography的调用,请问经过RANSAC挑选适合的特征点后,
是用什么方法求出八个参数? (Levenberg-Marquardt? gradient descent? 还是其他方法)
1、src_points,dst_points为N×2或者N×3的矩阵,N×2表示点是以像素坐标表示。N×3表示以齐次坐标表示。
2、homography,为3*3大小的矩阵,用来存储输出的结果。