Ask Your Question
0

MotionEstimatorRansacL2 no behaving as expected

asked 2017-06-12 04:14:50 -0500

enllauna gravatar image

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 flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-06-12 05:25:57 -0500

berak gravatar image

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]
edit flag offensive delete link more

Comments

Thanks! I really missed that detail. Now it works as expected! ;)

enllauna gravatar imageenllauna ( 2017-06-12 05:30:48 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2017-06-12 04:14:50 -0500

Seen: 80 times

Last updated: Jun 12 '17