Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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

like image 279
Isa Avatar asked Mar 19 '14 13:03

Isa


People also ask

How is homography calculated?

Thus, homography can be calculated using relative rotation and translation between two cameras.

Does homography include translation?

In the field of computer vision, any two images of the same planar surface in space are related by a homography (assuming a pinhole camera model). This has many practical applications, such as image rectification, image registration, or camera motion—rotation and translation—between two images.

How many points does it take to solve a homography?

We have seen that a homography can be used to map one image to the other in the case of pure camera rotation or a planar scene. If such a homography exists between the images, four points are sufficient to specify it precisely.

How many degrees of freedom does a 3x3 homography have?

The homography matrix is a 3x3 matrix but with 8 DoF (degrees of freedom) as it is estimated up to a scale.


2 Answers

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

like image 130
Vit Avatar answered Sep 28 '22 17:09

Vit


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

like image 38
Vlad Avatar answered Sep 28 '22 17:09

Vlad