Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: RZ_A2M_Mbed_samples
blenders.hpp
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 #if defined(NO) 00047 # warning Detected Apple 'NO' macro definition, it can cause build conflicts. Please, include this header before any Apple headers. 00048 #endif 00049 00050 #include "opencv2/core.hpp" 00051 00052 namespace cv { 00053 namespace detail { 00054 00055 //! @addtogroup stitching_blend 00056 //! @{ 00057 00058 /** @brief Base class for all blenders. 00059 00060 Simple blender which puts one image over another 00061 */ 00062 class CV_EXPORTS Blender 00063 { 00064 public: 00065 virtual ~Blender() {} 00066 00067 enum { NO, FEATHER, MULTI_BAND }; 00068 static Ptr<Blender> createDefault(int type, bool try_gpu = false); 00069 00070 /** @brief Prepares the blender for blending. 00071 00072 @param corners Source images top-left corners 00073 @param sizes Source image sizes 00074 */ 00075 void prepare(const std::vector<Point> &corners, const std::vector<Size> &sizes); 00076 /** @overload */ 00077 virtual void prepare(Rect dst_roi); 00078 /** @brief Processes the image. 00079 00080 @param img Source image 00081 @param mask Source image mask 00082 @param tl Source image top-left corners 00083 */ 00084 virtual void feed(InputArray img, InputArray mask, Point tl); 00085 /** @brief Blends and returns the final pano. 00086 00087 @param dst Final pano 00088 @param dst_mask Final pano mask 00089 */ 00090 virtual void blend(InputOutputArray dst, InputOutputArray dst_mask); 00091 00092 protected: 00093 UMat dst_, dst_mask_; 00094 Rect dst_roi_; 00095 }; 00096 00097 /** @brief Simple blender which mixes images at its borders. 00098 */ 00099 class CV_EXPORTS FeatherBlender : public Blender 00100 { 00101 public: 00102 FeatherBlender(float sharpness = 0.02f); 00103 00104 float sharpness() const { return sharpness_; } 00105 void setSharpness(float val) { sharpness_ = val; } 00106 00107 void prepare(Rect dst_roi); 00108 void feed(InputArray img, InputArray mask, Point tl); 00109 void blend(InputOutputArray dst, InputOutputArray dst_mask); 00110 00111 //! Creates weight maps for fixed set of source images by their masks and top-left corners. 00112 //! Final image can be obtained by simple weighting of the source images. 00113 Rect createWeightMaps(const std::vector<UMat> &masks, const std::vector<Point> &corners, 00114 std::vector<UMat> &weight_maps); 00115 00116 private: 00117 float sharpness_; 00118 UMat weight_map_; 00119 UMat dst_weight_map_; 00120 }; 00121 00122 inline FeatherBlender::FeatherBlender(float _sharpness) { setSharpness(_sharpness); } 00123 00124 /** @brief Blender which uses multi-band blending algorithm (see @cite BA83). 00125 */ 00126 class CV_EXPORTS MultiBandBlender : public Blender 00127 { 00128 public: 00129 MultiBandBlender(int try_gpu = false, int num_bands = 5, int weight_type = CV_32F); 00130 00131 int numBands() const { return actual_num_bands_; } 00132 void setNumBands(int val) { actual_num_bands_ = val; } 00133 00134 void prepare(Rect dst_roi); 00135 void feed(InputArray img, InputArray mask, Point tl); 00136 void blend(InputOutputArray dst, InputOutputArray dst_mask); 00137 00138 private: 00139 int actual_num_bands_, num_bands_; 00140 std::vector<UMat> dst_pyr_laplace_; 00141 std::vector<UMat> dst_band_weights_; 00142 Rect dst_roi_final_; 00143 bool can_use_gpu_; 00144 int weight_type_; //CV_32F or CV_16S 00145 }; 00146 00147 00148 ////////////////////////////////////////////////////////////////////////////// 00149 // Auxiliary functions 00150 00151 void CV_EXPORTS normalizeUsingWeightMap(InputArray weight, InputOutputArray src); 00152 00153 void CV_EXPORTS createWeightMap(InputArray mask, float sharpness, InputOutputArray weight); 00154 00155 void CV_EXPORTS createLaplacePyr(InputArray img, int num_levels, std::vector<UMat>& pyr); 00156 void CV_EXPORTS createLaplacePyrGpu(InputArray img, int num_levels, std::vector<UMat>& pyr); 00157 00158 // Restores source image 00159 void CV_EXPORTS restoreImageFromLaplacePyr(std::vector<UMat>& pyr); 00160 void CV_EXPORTS restoreImageFromLaplacePyrGpu(std::vector<UMat>& pyr); 00161 00162 //! @} 00163 00164 } // namespace detail 00165 } // namespace cv 00166 00167 #endif // OPENCV_STITCHING_BLENDERS_HPP
Generated on Tue Jul 12 2022 18:20:16 by
