1/*M/////////////////////////////////////////////////////////////////////////////////////// 2// 3// IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. 4// 5// By downloading, copying, installing or using the software you agree to this license. 6// If you do not agree to this license, do not download, install, 7// copy or use the software. 8// 9// 10// License Agreement 11// For Open Source Computer Vision Library 12// 13// Copyright (C) 2000-2008, Intel Corporation, all rights reserved. 14// Copyright (C) 2009, Willow Garage Inc., all rights reserved. 15// Third party copyrights are property of their respective owners. 16// 17// Redistribution and use in source and binary forms, with or without modification, 18// are permitted provided that the following conditions are met: 19// 20// * Redistribution's of source code must retain the above copyright notice, 21// this list of conditions and the following disclaimer. 22// 23// * Redistribution's in binary form must reproduce the above copyright notice, 24// this list of conditions and the following disclaimer in the documentation 25// and/or other materials provided with the distribution. 26// 27// * The name of the copyright holders may not be used to endorse or promote products 28// derived from this software without specific prior written permission. 29// 30// This software is provided by the copyright holders and contributors "as is" and 31// any express or implied warranties, including, but not limited to, the implied 32// warranties of merchantability and fitness for a particular purpose are disclaimed. 33// In no event shall the Intel Corporation or contributors be liable for any direct, 34// indirect, incidental, special, exemplary, or consequential damages 35// (including, but not limited to, procurement of substitute goods or services; 36// loss of use, data, or profits; or business interruption) however caused 37// and on any theory of liability, whether in contract, strict liability, 38// or tort (including negligence or otherwise) arising in any way out of 39// the use of this software, even if advised of the possibility of such damage. 40// 41//M*/ 42 43#ifndef __OPENCV_STITCHING_BLENDERS_HPP__ 44#define __OPENCV_STITCHING_BLENDERS_HPP__ 45 46#include "opencv2/core.hpp" 47 48namespace cv { 49namespace detail { 50 51//! @addtogroup stitching_blend 52//! @{ 53 54/** @brief Base class for all blenders. 55 56Simple blender which puts one image over another 57*/ 58class CV_EXPORTS Blender 59{ 60public: 61 virtual ~Blender() {} 62 63 enum { NO, FEATHER, MULTI_BAND }; 64 static Ptr<Blender> createDefault(int type, bool try_gpu = false); 65 66 /** @brief Prepares the blender for blending. 67 68 @param corners Source images top-left corners 69 @param sizes Source image sizes 70 */ 71 void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes); 72 /** @overload */ 73 virtual void prepare(Rect dst_roi); 74 /** @brief Processes the image. 75 76 @param img Source image 77 @param mask Source image mask 78 @param tl Source image top-left corners 79 */ 80 virtual void feed(InputArray img, InputArray mask, Point tl); 81 /** @brief Blends and returns the final pano. 82 83 @param dst Final pano 84 @param dst_mask Final pano mask 85 */ 86 virtual void blend(InputOutputArray dst, InputOutputArray dst_mask); 87 88protected: 89 UMat dst_, dst_mask_; 90 Rect dst_roi_; 91}; 92 93/** @brief Simple blender which mixes images at its borders. 94 */ 95class CV_EXPORTS FeatherBlender : public Blender 96{ 97public: 98 FeatherBlender(float sharpness = 0.02f); 99 100 float sharpness() const { return sharpness_; } 101 void setSharpness(float val) { sharpness_ = val; } 102 103 void prepare(Rect dst_roi); 104 void feed(InputArray img, InputArray mask, Point tl); 105 void blend(InputOutputArray dst, InputOutputArray dst_mask); 106 107 //! Creates weight maps for fixed set of source images by their masks and top-left corners. 108 //! Final image can be obtained by simple weighting of the source images. 109 Rect createWeightMaps(const std::vector<UMat> &masks, const std::vector<Point> &corners, 110 std::vector<UMat> &weight_maps); 111 112private: 113 float sharpness_; 114 UMat weight_map_; 115 UMat dst_weight_map_; 116}; 117 118inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); } 119 120/** @brief Blender which uses multi-band blending algorithm (see @cite BA83). 121 */ 122class CV_EXPORTS MultiBandBlender : public Blender 123{ 124public: 125 MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F); 126 127 int numBands() const { return actual_num_bands_; } 128 void setNumBands(int val) { actual_num_bands_ = val; } 129 130 void prepare(Rect dst_roi); 131 void feed(InputArray img, InputArray mask, Point tl); 132 void blend(InputOutputArray dst, InputOutputArray dst_mask); 133 134private: 135 int actual_num_bands_, num_bands_; 136 std::vector<UMat> dst_pyr_laplace_; 137 std::vector<UMat> dst_band_weights_; 138 Rect dst_roi_final_; 139 bool can_use_gpu_; 140 int weight_type_; //CV_32F or CV_16S 141}; 142 143 144////////////////////////////////////////////////////////////////////////////// 145// Auxiliary functions 146 147void CV_EXPORTS normalizeUsingWeightMap(InputArray weight, InputOutputArray src); 148 149void CV_EXPORTS createWeightMap(InputArray mask, float sharpness, InputOutputArray weight); 150 151void CV_EXPORTS createLaplacePyr(InputArray img, int num_levels, std::vector<UMat>& pyr); 152void CV_EXPORTS createLaplacePyrGpu(InputArray img, int num_levels, std::vector<UMat>& pyr); 153 154// Restores source image 155void CV_EXPORTS restoreImageFromLaplacePyr(std::vector<UMat>& pyr); 156void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector<UMat>& pyr); 157 158//! @} 159 160} // namespace detail 161} // namespace cv 162 163#endif // __OPENCV_STITCHING_BLENDERS_HPP__ 164