Calculate a Homography with only Translation, Rotation and Scale in Opencv

大憨熊 提交于 2020-01-22 09:56:18

问题


I do have two sets of points and I want to find the best transformation between them. In OpenCV, you have the following function:

Mat H = Calib3d.findHomography(src_points, dest_points);

that returns you a 3x3 Homography matrix, using RANSAC. My problem is now, that I only need translation and rotation (& maybe scale), I don't need affine and perspective.

The thing is, my points are only in 2D.

(1) Is there a function to compute something like a homography but with less degrees of freedom?

(2) If there is none, is it possible to extract a 3x3 matrix that does only translation and rotation from the 3x3 homography matrix?

Thanks in advance for any help!

Isa


回答1:


OpenCV estimateRigidTransform function is exactly what you need: it returns Translation, Rotation and Scale (use false value for fullAffine flag). And it DOES use RANSAC (see source code to be sure of it).




回答2:


Homography is for 2D points, the third dimension is just for casting points in 3 dim homogeneous coordinates and performing perspective effects. You can always cast points back:

homogeneous [x, y, w] cartesian [x/w, y/w]

However since you calculate 6DOF instead of 4DOF (similarity) you result is pretty different from what you expect with 4DOF. More flexible transformation will fit more points in RANSAC at the expense of distortions in transformations you care about. Bottom line - don’t try to decompose H, instead fit similarity or isometry (also called rigid or euclidean). The reason why they are absent in the library - they are expressed in closed form even with correct least squared metric in point coordinates and thus don't require non-linear optimization. In other words, they are very simple.

If you only have rotation and translation, I wrote a quick functions to find them (no RANSAC though). It is probably similar to a rigidTransform but more understandable (hopefully) https://stackoverflow.com/a/18091472/457687

With scale there is still a closed form solution, but slightly different formulas for translation and scaling. See Learning similarity parameters, p. 25



来源:https://stackoverflow.com/questions/22507745/calculate-a-homography-with-only-translation-rotation-and-scale-in-opencv

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!