added exposure compensation base class into opencv_stitching
authorAlexey Spizhevoy <no@email>
Tue, 24 May 2011 13:59:02 +0000 (13:59 +0000)
committerAlexey Spizhevoy <no@email>
Tue, 24 May 2011 13:59:02 +0000 (13:59 +0000)
modules/stitching/exposure_compensate.cpp [new file with mode: 0644]
modules/stitching/exposure_compensate.hpp [new file with mode: 0644]
modules/stitching/main.cpp

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