blenders.hpp
Go to the documentation of this file.
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/core.hpp"
47 
48 namespace cv {
49 namespace detail {
50 
51 
52 // Simple blender which puts one image over another
53 class CV_EXPORTS Blender
54 {
55 public:
56  virtual ~Blender() {}
57 
58  enum { NO, FEATHER, MULTI_BAND };
59  static Ptr<Blender> createDefault(int type, bool try_gpu = false);
60 
61  void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes);
62  virtual void prepare(Rect dst_roi);
63  virtual void feed(const Mat &img, const Mat &mask, Point tl);
64  virtual void blend(Mat &dst, Mat &dst_mask);
65 
66 protected:
67  Mat dst_, dst_mask_;
69 };
70 
71 
72 class CV_EXPORTS FeatherBlender : public Blender
73 {
74 public:
75  FeatherBlender(float sharpness = 0.02f);
76 
77  float sharpness() const { return sharpness_; }
78  void setSharpness(float val) { sharpness_ = val; }
79 
80  void prepare(Rect dst_roi);
81  void feed(const Mat &img, const Mat &mask, Point tl);
82  void blend(Mat &dst, Mat &dst_mask);
83 
84  // Creates weight maps for fixed set of source images by their masks and top-left corners.
85  // Final image can be obtained by simple weighting of the source images.
86  Rect createWeightMaps(const std::vector<Mat> &masks, const std::vector<Point> &corners,
87  std::vector<Mat> &weight_maps);
88 
89 private:
90  float sharpness_;
91  Mat weight_map_;
92  Mat dst_weight_map_;
93 };
94 
95 inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); }
96 
97 
98 class CV_EXPORTS MultiBandBlender : public Blender
99 {
100 public:
101  MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F);
102 
103  int numBands() const { return actual_num_bands_; }
104  void setNumBands(int val) { actual_num_bands_ = val; }
105 
106  void prepare(Rect dst_roi);
107  void feed(const Mat &img, const Mat &mask, Point tl);
108  void blend(Mat &dst, Mat &dst_mask);
109 
110 private:
111  int actual_num_bands_, num_bands_;
112  std::vector<Mat> dst_pyr_laplace_;
113  std::vector<Mat> dst_band_weights_;
114  Rect dst_roi_final_;
115  bool can_use_gpu_;
116  int weight_type_; //CV_32F or CV_16S
117 };
118 
119 
121 // Auxiliary functions
122 
123 void CV_EXPORTS normalizeUsingWeightMap(const Mat& weight, Mat& src);
124 
125 void CV_EXPORTS createWeightMap(const Mat& mask, float sharpness, Mat& weight);
126 
127 void CV_EXPORTS createLaplacePyr(const Mat &img, int num_levels, std::vector<Mat>& pyr);
128 void CV_EXPORTS createLaplacePyrGpu(const Mat &img, int num_levels, std::vector<Mat>& pyr);
129 
130 // Restores source image
131 void CV_EXPORTS restoreImageFromLaplacePyr(std::vector<Mat>& pyr);
132 void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector<Mat>& pyr);
133 
134 } // namespace detail
135 } // namespace cv
136 
137 #endif // __OPENCV_STITCHING_BLENDERS_HPP__
int numBands() const
Definition: blenders.hpp:103
Definition: blenders.hpp:72
const int * sizes
Definition: core_c.h:212
virtual ~Blender()
Definition: blenders.hpp:56
Definition: blenders.hpp:58
void CV_EXPORTS createLaplacePyrGpu(const Mat &img, int num_levels, std::vector< Mat > &pyr)
GLuint src
Definition: core_c.h:1650
void CV_EXPORTS createLaplacePyr(const Mat &img, int num_levels, std::vector< Mat > &pyr)
void setSharpness(float val)
Definition: blenders.hpp:78
void blend(Surface *background, const Surface &foreground, const Area &srcArea, const Vec2i &dstRelativeOffset=Vec2i::zero())
GLint GLvoid * img
Definition: legacy.hpp:1150
Rect dst_roi_
Definition: blenders.hpp:68
float sharpness() const
Definition: blenders.hpp:77
GLuint GLfloat * val
void CV_EXPORTS restoreImageFromLaplacePyr(std::vector< Mat > &pyr)
void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector< Mat > &pyr)
Definition: blenders.hpp:53
Definition: blenders.hpp:98
void CV_EXPORTS normalizeUsingWeightMap(const Mat &weight, Mat &src)
FeatherBlender(float sharpness=0.02f)
Definition: blenders.hpp:95
void setNumBands(int val)
Definition: blenders.hpp:104
The Core Functionality.
The n-dimensional matrix class.
Definition: core.hpp:1688
CvSize CvPoint2D32f * corners
Definition: calib3d.hpp:215
GLuint GLuint GLsizei GLenum type
Definition: core_c.h:114
template 2D point class.
Definition: core.hpp:82
void CV_EXPORTS createWeightMap(const Mat &mask, float sharpness, Mat &weight)
GLuint dst
Definition: calib3d.hpp:134
Smart pointer to dynamically allocated objects.
Definition: core.hpp:1268
Mat dst_mask_
Definition: blenders.hpp:67
GLenum GLint GLuint mask
Definition: tracking.hpp:132
GLclampf f