From 15173fc5591207a743178e344d35e685848cee33 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Fri, 6 May 2011 06:20:41 +0000 Subject: [PATCH] added wave correct support into opencv_stitching --- modules/stitching/main.cpp | 42 ++++++++++++++++++--------------- modules/stitching/motion_estimators.cpp | 8 ++++--- 2 files changed, 28 insertions(+), 22 deletions(-) diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index 9468edb..6a23286 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -11,16 +11,20 @@ using namespace cv; void printUsage() { - cout << "Rotation model images stitcher.\n" - << "Usage: opencv_stitching img1 img2 [...imgN]\n" - << "\t[--matchconf <0.0-1.0>]\n" + cout << "Rotation model images stitcher.\n\n"; + cout << "Usage: opencv_stitching img1 img2 [...imgN]\n" + << "\t[--matchconf ]\n" << "\t[--ba (ray|focal_ray)]\n" << "\t[--ba_thresh ]\n" - //<< "\t[--wavecorrect (no|yes)]\n" + << "\t[--wavecorrect (no|yes)]\n" << "\t[--warp (plane|cylindrical|spherical)]\n" << "\t[--seam (no|voronoi|graphcut)]\n" << "\t[--blend (no|feather|multiband)]\n" - << "\t[--output ]\n"; + << "\t[--output ]\n\n"; + cout << "--matchconf\n" + << "\tGood values are in [0.2, 0.8] range usually.\n\n"; + cout << "--ba_thresh\n" + << "\tGood values are in [0.3, 1.0] range usually.\n"; } int main(int argc, char* argv[]) @@ -29,7 +33,7 @@ int main(int argc, char* argv[]) vector images; string result_name = "result.png"; - int ba_space = BundleAdjuster::RAY_SPACE; + int ba_space = BundleAdjuster::FOCAL_RAY_SPACE; float ba_thresh = 1.f; bool wave_correct = false; int warp_type = Warper::SPHERICAL; @@ -75,19 +79,19 @@ int main(int argc, char* argv[]) ba_thresh = static_cast(atof(argv[i + 1])); i++; } - //else if (string(argv[i]) == "--wavecorrect") - //{ - // if (string(argv[i + 1]) == "no") - // wave_correct = false; - // else if (string(argv[i + 1]) == "yes") - // wave_correct = true; - // else - // { - // cout << "Bad wave correct flag value\n"; - // return -1; - // } - // i++; - //} + else if (string(argv[i]) == "--wavecorrect") + { + if (string(argv[i + 1]) == "no") + wave_correct = false; + else if (string(argv[i + 1]) == "yes") + wave_correct = true; + else + { + cout << "Bad wave correct flag value\n"; + return -1; + } + i++; + } else if (string(argv[i]) == "--warp") { if (string(argv[i + 1]) == "plane") diff --git a/modules/stitching/motion_estimators.cpp b/modules/stitching/motion_estimators.cpp index 2d2f02d..0974e1a 100644 --- a/modules/stitching/motion_estimators.cpp +++ b/modules/stitching/motion_estimators.cpp @@ -685,7 +685,6 @@ void BundleAdjuster::calcJacobian() ////////////////////////////////////////////////////////////////////////////// -// TODO test on adobe/halfdome void waveCorrect(vector &rmats) { float data[9]; @@ -710,10 +709,13 @@ void waveCorrect(vector &rmats) Mat avgz = Mat::zeros(3, 1, CV_32F); for (size_t i = 0; i < rmats.size(); ++i) avgz += rmats[i].col(2); - avgz.t().cross(r1).copyTo(r0); + r1.cross(avgz.t()).copyTo(r0); normalize(r0, r0); - r0.cross(r1).copyTo(r2); + r1.cross(r0).copyTo(r2); + + if (determinant(R) < 0) + R *= -1; for (size_t i = 0; i < rmats.size(); ++i) rmats[i] = R * rmats[i]; -- 2.7.4