added exposure compensation base class into opencv_stitching
This commit is contained in:
parent
7659c77619
commit
00a72d48af
47
modules/stitching/exposure_compensate.cpp
Normal file
47
modules/stitching/exposure_compensate.cpp
Normal file
@ -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;
|
64
modules/stitching/exposure_compensate.hpp
Normal file
64
modules/stitching/exposure_compensate.hpp
Normal file
@ -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<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__
|
@ -45,6 +45,7 @@
|
|||||||
#include "blenders.hpp"
|
#include "blenders.hpp"
|
||||||
#include "seam_finders.hpp"
|
#include "seam_finders.hpp"
|
||||||
#include "motion_estimators.hpp"
|
#include "motion_estimators.hpp"
|
||||||
|
#include "exposure_compensate.hpp"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace cv;
|
using namespace cv;
|
||||||
@ -407,13 +408,16 @@ int main(int argc, char* argv[])
|
|||||||
|
|
||||||
LOGLN("Warping images, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Warping images, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
|
||||||
|
LOGLN("Exposure compensation (feed)...");
|
||||||
|
t = getTickCount();
|
||||||
|
Ptr<ExposureCompensator> compensator = new NoExposureCompensator();
|
||||||
|
compensator->feed(images_warped, masks_warped);
|
||||||
|
LOGLN("Exposure compensation (feed), time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
|
||||||
LOGLN("Finding seams...");
|
LOGLN("Finding seams...");
|
||||||
t = getTickCount();
|
t = getTickCount();
|
||||||
|
|
||||||
// Find seams
|
|
||||||
Ptr<SeamFinder> seam_finder = SeamFinder::createDefault(seam_find_type);
|
Ptr<SeamFinder> seam_finder = SeamFinder::createDefault(seam_find_type);
|
||||||
seam_finder->find(images_warped_f, corners, masks_warped);
|
seam_finder->find(images_warped_f, corners, masks_warped);
|
||||||
|
|
||||||
LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
LOGLN("Finding seams, time: " << ((getTickCount() - t) / getTickFrequency()) << " sec");
|
||||||
|
|
||||||
// Release unused memory
|
// Release unused memory
|
||||||
@ -460,16 +464,21 @@ int main(int argc, char* argv[])
|
|||||||
// Warp the current image
|
// Warp the current image
|
||||||
warper->warp(img, static_cast<float>(cameras[img_idx].focal), cameras[img_idx].R,
|
warper->warp(img, static_cast<float>(cameras[img_idx].focal), cameras[img_idx].R,
|
||||||
img_warped);
|
img_warped);
|
||||||
img_warped.convertTo(img_warped_s, CV_16S);
|
|
||||||
img_warped.release();
|
|
||||||
img.release();
|
|
||||||
|
|
||||||
// Warp current image mask
|
// Warp current image mask
|
||||||
mask.create(img_size, CV_8U);
|
mask.create(img_size, CV_8U);
|
||||||
mask.setTo(Scalar::all(255));
|
mask.setTo(Scalar::all(255));
|
||||||
warper->warp(mask, static_cast<float>(cameras[img_idx].focal), cameras[img_idx].R, mask_warped,
|
warper->warp(mask, static_cast<float>(cameras[img_idx].focal), cameras[img_idx].R, mask_warped,
|
||||||
INTER_NEAREST, BORDER_CONSTANT);
|
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();
|
mask.release();
|
||||||
|
|
||||||
dilate(masks_warped[img_idx], dilated_mask, Mat());
|
dilate(masks_warped[img_idx], dilated_mask, Mat());
|
||||||
resize(dilated_mask, seam_mask, mask_warped.size());
|
resize(dilated_mask, seam_mask, mask_warped.size());
|
||||||
mask_warped = seam_mask & mask_warped;
|
mask_warped = seam_mask & mask_warped;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user