include/opencv2/stitching/detail/blenders.hpp
Go to the documentation of this file.
00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                          License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
00014 // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
00015 // Third party copyrights are property of their respective owners.
00016 //
00017 // Redistribution and use in source and binary forms, with or without modification,
00018 // are permitted provided that the following conditions are met:
00019 //
00020 //   * Redistribution's of source code must retain the above copyright notice,
00021 //     this list of conditions and the following disclaimer.
00022 //
00023 //   * Redistribution's in binary form must reproduce the above copyright notice,
00024 //     this list of conditions and the following disclaimer in the documentation
00025 //     and/or other materials provided with the distribution.
00026 //
00027 //   * The name of the copyright holders may not be used to endorse or promote products
00028 //     derived from this software without specific prior written permission.
00029 //
00030 // This software is provided by the copyright holders and contributors "as is" and
00031 // any express or implied warranties, including, but not limited to, the implied
00032 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00033 // In no event shall the Intel Corporation or contributors be liable for any direct,
00034 // indirect, incidental, special, exemplary, or consequential damages
00035 // (including, but not limited to, procurement of substitute goods or services;
00036 // loss of use, data, or profits; or business interruption) however caused
00037 // and on any theory of liability, whether in contract, strict liability,
00038 // or tort (including negligence or otherwise) arising in any way out of
00039 // the use of this software, even if advised of the possibility of such damage.
00040 //
00041 //M*/
00042 
00043 #ifndef __OPENCV_STITCHING_BLENDERS_HPP__
00044 #define __OPENCV_STITCHING_BLENDERS_HPP__
00045 
00046 #include "opencv2/core/core.hpp"
00047 
00048 namespace cv {
00049 namespace detail {
00050 
00051 
00052 // Simple blender which puts one image over another
00053 class CV_EXPORTS Blender
00054 {
00055 public:
00056     virtual ~Blender() {}
00057 
00058     enum { NO, FEATHER, MULTI_BAND };
00059     static Ptr<Blender> createDefault(int type, bool try_gpu = false);
00060 
00061     void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes);
00062     virtual void prepare(Rect dst_roi);
00063     virtual void feed(const Mat &img, const Mat &mask, Point tl);
00064     virtual void blend(Mat &dst, Mat &dst_mask);
00065 
00066 protected:
00067     Mat dst_, dst_mask_;
00068     Rect dst_roi_;
00069 };
00070 
00071 
00072 class CV_EXPORTS FeatherBlender : public Blender
00073 {
00074 public:
00075     FeatherBlender(float sharpness = 0.02f);
00076 
00077     float sharpness() const { return sharpness_; }
00078     void setSharpness(float val) { sharpness_ = val; }
00079 
00080     void prepare(Rect dst_roi);
00081     void feed(const Mat &img, const Mat &mask, Point tl);
00082     void blend(Mat &dst, Mat &dst_mask);
00083 
00084     // Creates weight maps for fixed set of source images by their masks and top-left corners.
00085     // Final image can be obtained by simple weighting of the source images.
00086     Rect createWeightMaps(const std::vector<Mat> &masks, const std::vector<Point> &corners,
00087                           std::vector<Mat> &weight_maps);
00088 
00089 private:
00090     float sharpness_;
00091     Mat weight_map_;
00092     Mat dst_weight_map_;
00093 };
00094 
00095 inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); }
00096 
00097 
00098 class CV_EXPORTS MultiBandBlender : public Blender
00099 {
00100 public:
00101     MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F);
00102 
00103     int numBands() const { return actual_num_bands_; }
00104     void setNumBands(int val) { actual_num_bands_ = val; }
00105 
00106     void prepare(Rect dst_roi);
00107     void feed(const Mat &img, const Mat &mask, Point tl);
00108     void blend(Mat &dst, Mat &dst_mask);
00109 
00110 private:
00111     int actual_num_bands_, num_bands_;
00112     std::vector<Mat> dst_pyr_laplace_;
00113     std::vector<Mat> dst_band_weights_;
00114     Rect dst_roi_final_;
00115     bool can_use_gpu_;
00116     int weight_type_; //CV_32F or CV_16S
00117 };
00118 
00119 
00121 // Auxiliary functions
00122 
00123 void CV_EXPORTS normalizeUsingWeightMap(const Mat& weight, Mat& src);
00124 
00125 void CV_EXPORTS createWeightMap(const Mat& mask, float sharpness, Mat& weight);
00126 
00127 void CV_EXPORTS createLaplacePyr(const Mat &img, int num_levels, std::vector<Mat>& pyr);
00128 void CV_EXPORTS createLaplacePyrGpu(const Mat &img, int num_levels, std::vector<Mat>& pyr);
00129 
00130 // Restores source image
00131 void CV_EXPORTS restoreImageFromLaplacePyr(std::vector<Mat>& pyr);
00132 void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector<Mat>& pyr);
00133 
00134 } // namespace detail
00135 } // namespace cv
00136 
00137 #endif // __OPENCV_STITCHING_BLENDERS_HPP__