Added support of homography motion model into vidostab sample

This commit is contained in:
Alexey Spizhevoy 2012-04-06 10:51:46 +00:00
parent d9d4755387
commit 30b461a506

View File

@ -65,7 +65,7 @@ void printHelp()
cout << "OpenCV video stabilizer.\n" cout << "OpenCV video stabilizer.\n"
"Usage: videostab <file_path> [arguments]\n\n" "Usage: videostab <file_path> [arguments]\n\n"
"Arguments:\n" "Arguments:\n"
" -m, --model=(transl|transl_and_scale|linear_sim|affine)\n" " -m, --model=(transl|transl_and_scale|linear_sim|affine|homography)\n"
" Set motion model. The default is affine.\n" " Set motion model. The default is affine.\n"
" --outlier-ratio=<float_number>\n" " --outlier-ratio=<float_number>\n"
" Outliers ratio in motion estimation. The default is 0.5.\n" " Outliers ratio in motion estimation. The default is 0.5.\n"
@ -232,30 +232,34 @@ int main(int argc, const char **argv)
if (arg("fps") == "auto") outputFps = source->fps(); else outputFps = argd("fps"); if (arg("fps") == "auto") outputFps = source->fps(); else outputFps = argd("fps");
stabilizer->setFrameSource(source); stabilizer->setFrameSource(source);
if (arg("load-motions") == "no") PyrLkRobustMotionEstimator *est = 0;
{ if (arg("model") == "transl")
PyrLkRobustMotionEstimator *est = 0; est = new PyrLkRobustMotionEstimator(TRANSLATION);
if (arg("model") == "transl") else if (arg("model") == "transl_and_scale")
est = new PyrLkRobustMotionEstimator(TRANSLATION); est = new PyrLkRobustMotionEstimator(TRANSLATION_AND_SCALE);
else if (arg("model") == "transl_and_scale") else if (arg("model") == "linear_sim")
est = new PyrLkRobustMotionEstimator(TRANSLATION_AND_SCALE); est = new PyrLkRobustMotionEstimator(LINEAR_SIMILARITY);
else if (arg("model") == "linear_sim") else if (arg("model") == "affine")
est = new PyrLkRobustMotionEstimator(LINEAR_SIMILARITY); est = new PyrLkRobustMotionEstimator(AFFINE);
else if (arg("model") == "affine") else if (arg("model") == "homography")
est = new PyrLkRobustMotionEstimator(AFFINE); est = new PyrLkRobustMotionEstimator(HOMOGRAPHY);
else
{
delete est;
throw runtime_error("unknown motion model: " + arg("model"));
}
RansacParams ransac = est->ransacParams();
ransac.eps = argf("outlier-ratio");
est->setRansacParams(ransac);
est->setMinInlierRatio(argf("min-inlier-ratio"));
stabilizer->setMotionEstimator(est);
}
else else
{
delete est;
throw runtime_error("unknown motion model: " + arg("model"));
}
RansacParams ransac = est->ransacParams();
ransac.eps = argf("outlier-ratio");
est->setRansacParams(ransac);
est->setMinInlierRatio(argf("min-inlier-ratio"));
stabilizer->setMotionEstimator(est);
if (arg("load-motions") != "no")
{
MotionModel model = stabilizer->motionEstimator()->motionModel();
stabilizer->setMotionEstimator(new FromFileMotionReader(arg("load-motions"))); stabilizer->setMotionEstimator(new FromFileMotionReader(arg("load-motions")));
stabilizer->motionEstimator()->setMotionModel(model);
}
if (arg("save-motions") != "no") if (arg("save-motions") != "no")
stabilizer->setMotionEstimator( stabilizer->setMotionEstimator(