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