From 2395654cbf7935f150734b8ac0e9d4a814747527 Mon Sep 17 00:00:00 2001 From: Leonid Beynenson Date: Tue, 24 Jan 2012 11:56:32 +0000 Subject: [PATCH] Made changes in the stitching log macros: now the function stitchingLogLevel() may be used to make the stitching classes more/less verbose. --- .../include/opencv2/stitching/detail/util.hpp | 28 +++++++++++++++++++--- modules/stitching/src/matchers.cpp | 2 +- modules/stitching/src/motion_estimators.cpp | 12 +++++----- modules/stitching/src/util.cpp | 6 +++++ 4 files changed, 38 insertions(+), 10 deletions(-) diff --git a/modules/stitching/include/opencv2/stitching/detail/util.hpp b/modules/stitching/include/opencv2/stitching/detail/util.hpp index b304761..a2e5a02 100644 --- a/modules/stitching/include/opencv2/stitching/detail/util.hpp +++ b/modules/stitching/include/opencv2/stitching/detail/util.hpp @@ -54,7 +54,7 @@ #include #include #include - #define LOG(msg) \ + #define LOG_STITCHING_MSG(msg) \ do { \ std::stringstream _os; \ _os << msg; \ @@ -62,13 +62,33 @@ } while(0); #else #include - #define LOG(msg) do { std::cout << msg; std::cout.flush(); } while(0); + #define LOG_STITCHING_MSG(msg) do { std::cout << msg; std::cout.flush(); } while(0); #endif #else - #define LOG(msg) + #define LOG_STITCHING_MSG(msg) #endif +#define LOG_(_level, _msg) \ + do { \ + if ((_level) >= ::cv::detail::stitchingLogLevel()) { \ + LOG_STITCHING_MSG(_msg); \ + } \ + } while(0) + + +#define LOG(msg) LOG_(1, msg) +#define LOG_CHAT(msg) LOG_(0, msg) + #define LOGLN(msg) LOG(msg << std::endl) +#define LOGLN_CHAT(msg) LOG_CHAT(msg << std::endl) + +//#if DEBUG_LOG_CHAT +// #define LOG_CHAT(msg) LOG(msg) +// #define LOGLN_CHAT(msg) LOGLN(msg) +//#else +// #define LOG_CHAT(msg) do{}while(0) +// #define LOGLN_CHAT(msg) do{}while(0) +//#endif namespace cv { namespace detail { @@ -128,6 +148,8 @@ Point CV_EXPORTS resultTl(const std::vector &corners); // Returns random 'count' element subset of the {0,1,...,size-1} set void CV_EXPORTS selectRandomSubset(int count, int size, std::vector &subset); +int& CV_EXPORTS stitchingLogLevel(); + } // namespace detail } // namespace cv diff --git a/modules/stitching/src/matchers.cpp b/modules/stitching/src/matchers.cpp index aa8c0e9..cc1da49 100644 --- a/modules/stitching/src/matchers.cpp +++ b/modules/stitching/src/matchers.cpp @@ -491,7 +491,7 @@ void FeaturesMatcher::operator ()(const vector &features, vector< parallel_for(BlockedRange(0, static_cast(near_pairs.size())), body); else body(BlockedRange(0, static_cast(near_pairs.size()))); - LOGLN(""); + LOGLN_CHAT(""); } diff --git a/modules/stitching/src/motion_estimators.cpp b/modules/stitching/src/motion_estimators.cpp index 1d3aae0..acf2ad6c 100644 --- a/modules/stitching/src/motion_estimators.cpp +++ b/modules/stitching/src/motion_estimators.cpp @@ -171,7 +171,7 @@ void BundleAdjusterBase::estimate(const vector &features, const vector &pairwise_matches, vector &cameras) { - LOG("Bundle adjustment"); + LOG_CHAT("Bundle adjustment"); int64 t = getTickCount(); num_images_ = static_cast(features.size()); @@ -230,16 +230,16 @@ void BundleAdjusterBase::estimate(const vector &features, if (_err) { calcError(err); - LOG("."); + LOG_CHAT("."); iter++; CvMat tmp = err; cvCopy(&tmp, _err); } } - LOGLN(""); - LOGLN("Bundle adjustment, final RMS error: " << sqrt(err.dot(err) / total_num_matches_)); - LOGLN("Bundle adjustment, iterations done: " << iter); + LOGLN_CHAT(""); + LOGLN_CHAT("Bundle adjustment, final RMS error: " << sqrt(err.dot(err) / total_num_matches_)); + LOGLN_CHAT("Bundle adjustment, iterations done: " << iter); obtainRefinedCameraParams(cameras); @@ -251,7 +251,7 @@ void BundleAdjusterBase::estimate(const vector &features, for (int i = 0; i < num_images_; ++i) cameras[i].R = R_inv * cameras[i].R; - LOGLN("Bundle adjustment, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec"); + LOGLN_CHAT("Bundle adjustment, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec"); } diff --git a/modules/stitching/src/util.cpp b/modules/stitching/src/util.cpp index 3f6cff5..01206aa 100644 --- a/modules/stitching/src/util.cpp +++ b/modules/stitching/src/util.cpp @@ -165,5 +165,11 @@ void selectRandomSubset(int count, int size, vector &subset) } } +int& stitchingLogLevel() +{ + static int _log_level=1; + return _log_level; +} + } // namespace detail } // namespace cv -- 2.7.4