From 00a72d48af79361ad4a6ed6b4e2b36407b7fbea9 Mon Sep 17 00:00:00 2001 From: Alexey Spizhevoy Date: Tue, 24 May 2011 13:59:02 +0000 Subject: [PATCH] added exposure compensation base class into opencv_stitching --- modules/stitching/exposure_compensate.cpp | 47 +++++++++++++++++++++++ modules/stitching/exposure_compensate.hpp | 64 +++++++++++++++++++++++++++++++ modules/stitching/main.cpp | 21 +++++++--- 3 files changed, 126 insertions(+), 6 deletions(-) create mode 100644 modules/stitching/exposure_compensate.cpp create mode 100644 modules/stitching/exposure_compensate.hpp diff --git a/modules/stitching/exposure_compensate.cpp b/modules/stitching/exposure_compensate.cpp new file mode 100644 index 0000000..c449159 --- /dev/null +++ b/modules/stitching/exposure_compensate.cpp @@ -0,0 +1,47 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ + +#include "exposure_compensate.hpp" +#include "util.hpp" + +using namespace std; +using namespace cv; diff --git a/modules/stitching/exposure_compensate.hpp b/modules/stitching/exposure_compensate.hpp new file mode 100644 index 0000000..9793854 --- /dev/null +++ b/modules/stitching/exposure_compensate.hpp @@ -0,0 +1,64 @@ +/*M/////////////////////////////////////////////////////////////////////////////////////// +// +// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. +// +// By downloading, copying, installing or using the software you agree to this license. +// If you do not agree to this license, do not download, install, +// copy or use the software. +// +// +// License Agreement +// For Open Source Computer Vision Library +// +// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. +// Copyright (C) 2009, Willow Garage Inc., all rights reserved. +// Third party copyrights are property of their respective owners. +// +// Redistribution and use in source and binary forms, with or without modification, +// are permitted provided that the following conditions are met: +// +// * Redistribution's of source code must retain the above copyright notice, +// this list of conditions and the following disclaimer. +// +// * Redistribution's in binary form must reproduce the above copyright notice, +// this list of conditions and the following disclaimer in the documentation +// and/or other materials provided with the distribution. +// +// * The name of the copyright holders may not be used to endorse or promote products +// derived from this software without specific prior written permission. +// +// This software is provided by the copyright holders and contributors "as is" and +// any express or implied warranties, including, but not limited to, the implied +// warranties of merchantability and fitness for a particular purpose are disclaimed. +// In no event shall the Intel Corporation or contributors be liable for any direct, +// indirect, incidental, special, exemplary, or consequential damages +// (including, but not limited to, procurement of substitute goods or services; +// loss of use, data, or profits; or business interruption) however caused +// and on any theory of liability, whether in contract, strict liability, +// or tort (including negligence or otherwise) arising in any way out of +// the use of this software, even if advised of the possibility of such damage. +// +//M*/ +#ifndef __OPENCV_EXPOSURE_COMPENSATE_HPP__ +#define __OPENCV_EXPOSURE_COMPENSATE_HPP__ + +#include "precomp.hpp" + + +class ExposureCompensator +{ +public: + virtual void feed(const std::vector &images, const std::vector &masks) = 0; + virtual void apply(int index, cv::Mat &image, cv::Mat &mask) = 0; +}; + + +class NoExposureCompensator : public ExposureCompensator +{ +public: + virtual void feed(const std::vector &/*images*/, const std::vector &/*masks*/) {}; + virtual void apply(int /*index*/, cv::Mat &/*image*/, cv::Mat &/*mask*/) {}; +}; + + +#endif // __OPENCV_EXPOSURE_COMPENSATE_HPP__ \ No newline at end of file diff --git a/modules/stitching/main.cpp b/modules/stitching/main.cpp index ff8f3e8..9b47ca5 100644 --- a/modules/stitching/main.cpp +++ b/modules/stitching/main.cpp @@ -45,6 +45,7 @@ #include "blenders.hpp" #include "seam_finders.hpp" #include "motion_estimators.hpp" +#include "exposure_compensate.hpp" using namespace std; using namespace cv; @@ -407,13 +408,16 @@ int main(int argc, char* argv[]) LOGLN("Warping images, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec"); - LOGLN("Finding seams..."); + LOGLN("Exposure compensation (feed)..."); t = getTickCount(); + Ptr compensator = new NoExposureCompensator(); + compensator->feed(images_warped, masks_warped); + LOGLN("Exposure compensation (feed), time: " << ((getTickCount() - t) / getTickFrequency()) << " sec"); - // Find seams + LOGLN("Finding seams..."); + t = getTickCount(); Ptr seam_finder = SeamFinder::createDefault(seam_find_type); seam_finder->find(images_warped_f, corners, masks_warped); - LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec"); // Release unused memory @@ -460,16 +464,21 @@ int main(int argc, char* argv[]) // Warp the current image warper->warp(img, static_cast(cameras[img_idx].focal), cameras[img_idx].R, img_warped); - img_warped.convertTo(img_warped_s, CV_16S); - img_warped.release(); - img.release(); // Warp current image mask mask.create(img_size, CV_8U); mask.setTo(Scalar::all(255)); warper->warp(mask, static_cast(cameras[img_idx].focal), cameras[img_idx].R, mask_warped, INTER_NEAREST, BORDER_CONSTANT); + + // Compensate exposure + compensator->apply(img_idx, img_warped, mask_warped); + + img_warped.convertTo(img_warped_s, CV_16S); + img_warped.release(); + img.release(); mask.release(); + dilate(masks_warped[img_idx], dilated_mask, Mat()); resize(dilated_mask, seam_mask, mask_warped.size()); mask_warped = seam_mask & mask_warped; -- 2.7.4