estimateRigidTransform returns non sensical values

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++)
{
obj1.push_back(Point2f(i,i+10));
scene1.push_back(Point2f(i+10,i+20));
}
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 close merge delete

Sort by ยป oldest newest most voted

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

more
more

1

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

( 2013-08-14 03:25:34 -0600 )edit
1

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.

( 2013-08-14 07:23:52 -0600 )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!

( 2013-08-14 08:19:44 -0600 )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 :(

( 2014-02-26 04:10:34 -0600 )edit

Stats

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

Seen: 5,345 times

Last updated: Aug 14 '13