Skip to content

Commit f241a37

Browse files
committed
fix estimateGlobalMotionRansac;
1 parent ee257ff commit f241a37

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

modules/videostab/src/global_motion.cpp

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -402,8 +402,8 @@ Mat estimateGlobalMotionRansac(
402402
std::vector<Point2f> subset1(params.size);
403403

404404
// best hypothesis
405-
std::vector<Point2f> subset0best(params.size);
406-
std::vector<Point2f> subset1best(params.size);
405+
std::vector<int> bestIndices(params.size);
406+
407407
Mat_<float> bestM;
408408
int ninliersMax = -1;
409409

@@ -447,14 +447,20 @@ Mat estimateGlobalMotionRansac(
447447
{
448448
bestM = M;
449449
ninliersMax = numinliers;
450-
subset0best.swap(subset0);
451-
subset1best.swap(subset1);
450+
bestIndices.swap(indices);
452451
}
453452
}
454453

455454
if (ninliersMax < params.size)
455+
{
456456
// compute RMSE
457-
bestM = estimateGlobalMotionLeastSquares(subset0best, subset1best, model, rmse);
457+
for (int i = 0; i < params.size; ++i)
458+
{
459+
subset0[i] = points0_[bestIndices[i]];
460+
subset1[i] = points1_[bestIndices[i]];
461+
}
462+
bestM = estimateGlobalMotionLeastSquares(subset0, subset1, model, rmse);
463+
}
458464
else
459465
{
460466
subset0.resize(ninliersMax);

0 commit comments

Comments
 (0)