MotionEstimatorRansacL2 no behaving as expected

Dear all,

I would like to estimate the motion between 2 sets of keypoints using the method estimate of MotionEstimatorRansacL2. However it always returns the identity. I've created a toy code to figure it out:

// Create toy keypoints
int nKeypoints = 10;
int dx = 25;
std::vector<cv::KeyPoint> KP0, KP1;
for (int n = 0; n < nKeypoints; n++) {

cv::KeyPoint kp = cv::KeyPoint((float)n, (float)n, 2);
KP0.push_back(kp);
kp.pt.x += dx;
KP1.push_back(kp);
}

cv::videostab::MotionModel model = cv::videostab::MM_TRANSLATION;
cv::Ptr<cv::videostab::MotionEstimatorRansacL2> MotionEstimator = cv::makePtr<cv::videostab::MotionEstimatorRansacL2>(model);

bool estimationOK;
cv::Mat M = MotionEstimator->estimate(KP1, KP0, &estimationOK);


Any ideas and/or comments would be of great help.

Thanks!!

edit retag close merge delete

Sort by ยป oldest newest most voted

a quick look at the docs reveals, that it takes vector<Point2f> as input, not vector<KeyPoint> . so both your arrays, when checked, return -1 here and get rejected.

using Point2f , it should work:

int npoints = 10;
int dx = 25;
std::vector<Point2f> P0, P1;
for (int n = 0; n < npoints; n++) {

Point2f p((float)n, (float)n);
P0.push_back(p);
p.x += dx;
P1.push_back(p);
}

cv::videostab::MotionModel model = cv::videostab::MM_TRANSLATION;
cv::Ptr<cv::videostab::MotionEstimatorRansacL2> MotionEstimator = cv::makePtr<cv::videostab::MotionEstimatorRansacL2>(model);

bool estimationOK;
cv::Mat M = MotionEstimator->estimate(P1, P0, &estimationOK);
cout << estimationOK << M << endl;

1[1, 0, -25;
0, 1, 0;
0, 0, 1]

more