Ask Your Question

estimateRigidTransform returns non sensical values

asked 2013-04-03 16:23:59 -0500

HIy gravatar image

updated 2013-04-03 16:43:31 -0500

Guanta gravatar image

Hi all,

I am trying to estimate an affine transform from two point sets. Here is the sample code that I am running to verify estimateRigidTransform.

std::vector< Point2f > obj1;
std::vector< Point2f > scene1;
for (int i=0;i<10;i++)
Mat H1 = estimateRigidTransform(obj1,scene1,false);
cout << H1 << endl;

The output I get is:

[-4.836697827223e-026, -4.836697827223e-026, -4.836697827223e-026;
  -4.836697827223e-026, -4.836697827223e-026, -4.836697827223e-026]

What am I doing wrong?

Also, I would like to estimate the transformation robustly. Is there any sample code there for using RANSAC/or other robust methods on top of estimateRigidTransform?

Thanks HIy

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2013-08-14 04:25:07 -0500

Neptilo gravatar image

Your code looks right. However, to estimate an affine transformation you need at least 3 points, but if these points are all aligned, there is an infinity of solutions, which seems to lead the estimation to result in a degenerate solution.

Although that might no longer be true as you set fullAffine to false, perhaps the function is implemented in such a way that it still needs points that are not aligned. But that is a supposition.

What is the result if you add another point? For example:

obj1.push_back(Point2f(0, 0));
scene1.push_back(Point2f(10, 10));
edit flag offensive delete link more

answered 2013-04-19 10:33:37 -0500

Guanta gravatar image
edit flag offensive delete link more



What if we really want to use estimateRigidTransform? What is the right way to use it?

Neptilo gravatar imageNeptilo ( 2013-08-14 03:25:34 -0500 )edit

Haven't used estimateRigidTransform so far, but think @HIy actually calls it correctly. I also just checked the code (it is located in /modules/video/src/lkpyramid.cpp) and it seems that the transformation is actually computed via RANSAC but maybe its internal used thresholds are not very good chosen (e.g. RANSAC_GOOD_RATIO=0.5 seems pretty low). However RANSAC is really not difficult to compute on your own, so I'd use getAffineTransform with a self-implemented RANSAC-version.

Guanta gravatar imageGuanta ( 2013-08-14 07:23:52 -0500 )edit

I just downloaded the source code lkpyramid.cpp and set RANSAC's local parameters as arguments so I can modify whatever I want, haha!

Neptilo gravatar imageNeptilo ( 2013-08-14 08:19:44 -0500 )edit

@Neptilo: Hi, I have the same problem as you had so I also took the source from lkpyramid.cpp. Have you gotten it to work? Could you post a simple working example in that case? I suck at debugging :(

Tobbe gravatar imageTobbe ( 2014-02-26 04:10:34 -0500 )edit
Login/Signup to Answer

Question Tools


Asked: 2013-04-03 16:23:59 -0500

Seen: 4,758 times

Last updated: Aug 14 '13