diff --git a/modules/stitching/exposure_compensate.cpp b/modules/stitching/exposure_compensate.cpp new file mode 100644 index 0000000000..c449159a1f --- /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 0000000000..9793854f41 --- /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 ff8f3e81e1..9b47ca567c 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;