#ifndef __OPENCV_BLENDERS_HPP__ #define __OPENCV_BLENDERS_HPP__ #include #include // Simple blender which puts one image over another class Blender { public: enum { NO, FEATHER, MULTI_BAND }; static cv::Ptr createDefault(int type); cv::Point operator ()(const std::vector &src, const std::vector &corners, const std::vector &masks, cv::Mat& dst); cv::Point operator ()(const std::vector &src, const std::vector &corners, const std::vector &masks, cv::Mat& dst, cv::Mat& dst_mask); protected: virtual cv::Point blend(const std::vector &src, const std::vector &corners, const std::vector &masks, cv::Mat& dst, cv::Mat& dst_mask); }; class FeatherBlender : public Blender { public: FeatherBlender(float sharpness = 0.02f) : sharpness_(sharpness) {} private: cv::Point blend(const std::vector &src, const std::vector &corners, const std::vector &masks, cv::Mat &dst, cv::Mat &dst_mask); float sharpness_; }; class MultiBandBlender : public Blender { public: MultiBandBlender(int num_bands = 7) : num_bands_(num_bands) {} private: cv::Point blend(const std::vector &src, const std::vector &corners, const std::vector &masks, cv::Mat& dst, cv::Mat& dst_mask); int num_bands_; }; ////////////////////////////////////////////////////////////////////////////// // Auxiliary functions cv::Rect resultRoi(const std::vector &src, const std::vector &corners); cv::Point computeResultMask(const std::vector &masks, const std::vector &corners, cv::Mat &mask); cv::Point blendLinear(const std::vector &src, const std::vector &corners, const std::vector &weights, cv::Mat& dst, cv::Mat& dst_weight); void createWeightMap(const cv::Mat& mask, float sharpness, cv::Mat& weight); void createGaussPyr(const cv::Mat& img, int num_layers, std::vector& pyr); void createLaplacePyr(const std::vector& pyr_gauss, std::vector& pyr_laplace); // Restores source image in-place. Result will be in pyr[0]. void restoreImageFromLaplacePyr(std::vector& pyr); #endif // __OPENCV_BLENDERS_HPP__