OpenCV453
blenders.hpp
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#if defined(NO)
47# warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
48#endif
49
50#include "opencv2/core.hpp"
51#include "opencv2/core/cuda.hpp"
52
53namespace cv {
54namespace detail {
55
58
63class CV_EXPORTS_W Blender
64{
65public:
66 virtual ~Blender() {}
67
68 enum { NO, FEATHER, MULTI_BAND };
69 CV_WRAP static Ptr<Blender> createDefault(int type, bool try_gpu = false);
70
76 CV_WRAP virtual void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes);
78 CV_WRAP virtual void prepare(Rect dst_roi);
85 CV_WRAP virtual void feed(InputArray img, InputArray mask, Point tl);
91 CV_WRAP virtual void blend(CV_IN_OUT InputOutputArray dst,CV_IN_OUT InputOutputArray dst_mask);
92
93protected:
94 UMat dst_, dst_mask_;
95 Rect dst_roi_;
96};
97
100class CV_EXPORTS_W FeatherBlender : public Blender
101{
102public:
103 CV_WRAP FeatherBlender(float sharpness = 0.02f);
104
105 CV_WRAP float sharpness() const { return sharpness_; }
106 CV_WRAP void setSharpness(float val) { sharpness_ = val; }
107
108 CV_WRAP void prepare(Rect dst_roi) CV_OVERRIDE;
109 CV_WRAP void feed(InputArray img, InputArray mask, Point tl) CV_OVERRIDE;
110 CV_WRAP void blend(InputOutputArray dst, InputOutputArray dst_mask) CV_OVERRIDE;
111
114 CV_WRAP Rect createWeightMaps(const std::vector<UMat> &masks, const std::vector<Point> &corners,
115 CV_IN_OUT std::vector<UMat> &weight_maps);
116
117private:
118 float sharpness_;
119 UMat weight_map_;
120 UMat dst_weight_map_;
121};
122
123inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); }
124
127class CV_EXPORTS_W MultiBandBlender : public Blender
128{
129public:
130 CV_WRAP MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F);
131
132 CV_WRAP int numBands() const { return actual_num_bands_; }
133 CV_WRAP void setNumBands(int val) { actual_num_bands_ = val; }
134
135 CV_WRAP void prepare(Rect dst_roi) CV_OVERRIDE;
136 CV_WRAP void feed(InputArray img, InputArray mask, Point tl) CV_OVERRIDE;
137 CV_WRAP void blend(CV_IN_OUT InputOutputArray dst, CV_IN_OUT InputOutputArray dst_mask) CV_OVERRIDE;
138
139private:
140 int actual_num_bands_, num_bands_;
141 std::vector<UMat> dst_pyr_laplace_;
142 std::vector<UMat> dst_band_weights_;
143 Rect dst_roi_final_;
144 bool can_use_gpu_;
145 int weight_type_; //CV_32F or CV_16S
146#if defined(HAVE_OPENCV_CUDAARITHM) && defined(HAVE_OPENCV_CUDAWARPING)
147 std::vector<cuda::GpuMat> gpu_dst_pyr_laplace_;
148 std::vector<cuda::GpuMat> gpu_dst_band_weights_;
149 std::vector<Point> gpu_tl_points_;
150 std::vector<cuda::GpuMat> gpu_imgs_with_border_;
151 std::vector<std::vector<cuda::GpuMat> > gpu_weight_pyr_gauss_vec_;
152 std::vector<std::vector<cuda::GpuMat> > gpu_src_pyr_laplace_vec_;
153 std::vector<std::vector<cuda::GpuMat> > gpu_ups_;
154 cuda::GpuMat gpu_dst_mask_;
155 cuda::GpuMat gpu_mask_;
156 cuda::GpuMat gpu_img_;
157 cuda::GpuMat gpu_weight_map_;
158 cuda::GpuMat gpu_add_mask_;
159 int gpu_feed_idx_;
160 bool gpu_initialized_;
161#endif
162};
163
164
166// Auxiliary functions
167
168void CV_EXPORTS_W normalizeUsingWeightMap(InputArray weight, CV_IN_OUT InputOutputArray src);
169
170void CV_EXPORTS_W createWeightMap(InputArray mask, float sharpness, CV_IN_OUT InputOutputArray weight);
171
172void CV_EXPORTS_W createLaplacePyr(InputArray img, int num_levels, CV_IN_OUT std::vector<UMat>& pyr);
173void CV_EXPORTS_W createLaplacePyrGpu(InputArray img, int num_levels, CV_IN_OUT std::vector<UMat>& pyr);
174
175// Restores source image
176void CV_EXPORTS_W restoreImageFromLaplacePyr(CV_IN_OUT std::vector<UMat>& pyr);
177void CV_EXPORTS_W restoreImageFromLaplacePyrGpu(CV_IN_OUT std::vector<UMat>& pyr);
178
180
181} // namespace detail
182} // namespace cv
183
184#endif // OPENCV_STITCHING_BLENDERS_HPP
Definition: mat.hpp:386
Template class for 2D rectangles
Definition: core/types.hpp:421
Definition: mat.hpp:2402
Base storage class for GPU memory with reference counting.
Definition: core/cuda.hpp:106
Base class for all blenders.
Definition: blenders.hpp:64
Simple blender which mixes images at its borders.
Definition: blenders.hpp:101
Blender which uses multi-band blending algorithm (see ).
Definition: blenders.hpp:128
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75
Definition: cvstd_wrapper.hpp:74