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

前端 未结 2 663
感动是毒
感动是毒 2021-02-06 06:30

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         


        
相关标签:
2条回答
  • 2021-02-06 07:01

    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).

    0 讨论(0)
  • 2021-02-06 07:05

    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

    0 讨论(0)
提交回复
热议问题