8
votes

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

2
try estimateRigidTransform : docs.opencv.org/modules/video/doc/…Micka
if estimateRigidTransform isn't appropriate for you because it doesn't use RANSAC, you might have to progam your own RANSAC, which is not that hard. Unfortunately, as far as I know, openCV only provides outlier omitting transformation optimization for 8-dof homographies.Micka
Hey Micka, I tried estimateRigidTransform but it returns a Matrix of size 0x0. Arguments were the two point sets (of type MatOfPoint2f) and false because I only need translation, rotation & uniform scalingIsa
I never used estimateRigidTransform myself, so I can't help you how to use it. Maybe it returns an empty matrix because the src/dst point matrix isn't formatted correctly, or there are too many outlier which prevent computation of a rigid transform (since that function doesn't use RANSAC or other outlier control). But that's just a guess. In principle, a rigid transform is exactly what you asked for.Micka
here is an example of how to organize point samples to use them with that function: answers.opencv.org/question/10672/…Micka

2 Answers

8
votes

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

3
votes

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