/*M/////////////////////////////////////////////////////////////////////////////////////// // // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING. // // By downloading, copying, installing or using the software you agree to this license. // If you do not agree to this license, do not download, install, // copy or use the software. // // // License Agreement // For Open Source Computer Vision Library // // Copyright (C) 2000-2008, Intel Corporation, all rights reserved. // Copyright (C) 2009-2011, Willow Garage Inc., all rights reserved. // Third party copyrights are property of their respective owners. // // * Redistribution's of source code must retain the above copyright notice, // this list of conditions and the following disclaimer. // // * Redistribution's in binary form must reproduce the above copyright notice, // this list of conditions and the following disclaimer in the documentation // and/or other materials provided with the distribution. // // * The name of Intel Corporation may not be used to endorse or promote products // derived from this software without specific prior written permission. // // This software is provided by the copyright holders and contributors "as is" and // any express or implied warranties, including, but not limited to, the implied // warranties of merchantability and fitness for a particular purpose are disclaimed. // In no event shall the Intel Corporation or contributors be liable for any direct, // indirect, incidental, special, exemplary, or consequential damages // (including, but not limited to, procurement of substitute goods or services; // loss of use, data, or profits; or business interruption) however caused // and on any theory of liability, whether in contract, strict liability, // or tort (including negligence or otherwise) arising in any way out of // the use of this software, even if advised of the possibility of such damage. // //M*/ #include #include #include #include #include #include #include #include #include "opencv2/xphoto.hpp" #include "opencv2/imgproc.hpp" #include "opencv2/imgproc/imgproc_c.h" #include "opencv2/core.hpp" #include "opencv2/core/core_c.h" #include "opencv2/core/types.hpp" #include "opencv2/core/types_c.h" #include "opencv2/highgui.hpp" namespace xphotoInternal { # include "photomontage.hpp" # include "annf.hpp" } namespace cv { template static void shiftMapInpaint(const Mat &src, const Mat &mask, Mat &dst, const int nTransform = 60, const int psize = 8) { /** Preparing input **/ cv::Mat img; src.convertTo( img, CV_32F ); img.setTo(0, 255 - mask); /** ANNF computation **/ std::vector transforms( nTransform ); xphotoInternal::dominantTransforms(img, transforms, nTransform, psize); /** Warping **/ std::vector images( nTransform + 1 ); // source image transformed with transforms std::vector masks( nTransform + 1 ); // definition domain for current shift Mat_ invMask = 255 - mask; dilate(invMask, invMask, Mat(), Point(-1,-1), 2); img.copyTo( images[0] ); mask.copyTo( masks[0] ); for (int i = 0; i < nTransform; ++i) { warpPerspective( images[0], images[i + 1], transforms[i], images[0].size(), INTER_LINEAR ); warpPerspective( masks[0], masks[i + 1], transforms[i], masks[0].size(), INTER_NEAREST); masks[i + 1] &= invMask; } /** Stitching **/ Mat photomontageResult; xphotoInternal::Photomontage < cv::Vec >( images, masks ) .assignResImage(photomontageResult); /** Writing result **/ photomontageResult.convertTo( dst, dst.type() ); } template void inpaint(const Mat &src, const Mat &mask, Mat &dst, const int algorithmType) { dst.create( src.size(), src.type() ); switch ( algorithmType ) { case INPAINT_SHIFTMAP: shiftMapInpaint (src, mask, dst); break; default: CV_Error_( CV_StsNotImplemented, ("Unsupported algorithm type (=%d)", algorithmType) ); break; } } /*! The function reconstructs the selected image area from known area. * \param src : source image. * \param mask : inpainting mask, 8-bit 1-channel image. Zero pixels indicate the area that needs to be inpainted. * \param dst : destination image. * \param algorithmType : inpainting method. */ void inpaint(const Mat &src, const Mat &mask, Mat &dst, const int algorithmType) { CV_Assert( mask.channels() == 1 && mask.depth() == CV_8U ); CV_Assert( src.rows == mask.rows && src.cols == mask.cols ); switch ( src.type() ) { case CV_8SC1: inpaint ( src, mask, dst, algorithmType ); break; case CV_8SC2: inpaint ( src, mask, dst, algorithmType ); break; case CV_8SC3: inpaint ( src, mask, dst, algorithmType ); break; case CV_8SC4: inpaint ( src, mask, dst, algorithmType ); break; case CV_8UC1: inpaint ( src, mask, dst, algorithmType ); break; case CV_8UC2: inpaint ( src, mask, dst, algorithmType ); break; case CV_8UC3: inpaint ( src, mask, dst, algorithmType ); break; case CV_8UC4: inpaint ( src, mask, dst, algorithmType ); break; case CV_16SC1: inpaint ( src, mask, dst, algorithmType ); break; case CV_16SC2: inpaint ( src, mask, dst, algorithmType ); break; case CV_16SC3: inpaint ( src, mask, dst, algorithmType ); break; case CV_16SC4: inpaint ( src, mask, dst, algorithmType ); break; case CV_16UC1: inpaint ( src, mask, dst, algorithmType ); break; case CV_16UC2: inpaint ( src, mask, dst, algorithmType ); break; case CV_16UC3: inpaint ( src, mask, dst, algorithmType ); break; case CV_16UC4: inpaint ( src, mask, dst, algorithmType ); break; case CV_32SC1: inpaint ( src, mask, dst, algorithmType ); break; case CV_32SC2: inpaint ( src, mask, dst, algorithmType ); break; case CV_32SC3: inpaint ( src, mask, dst, algorithmType ); break; case CV_32SC4: inpaint ( src, mask, dst, algorithmType ); break; case CV_32FC1: inpaint ( src, mask, dst, algorithmType ); break; case CV_32FC2: inpaint ( src, mask, dst, algorithmType ); break; case CV_32FC3: inpaint ( src, mask, dst, algorithmType ); break; case CV_32FC4: inpaint ( src, mask, dst, algorithmType ); break; case CV_64FC1: inpaint ( src, mask, dst, algorithmType ); break; case CV_64FC2: inpaint ( src, mask, dst, algorithmType ); break; case CV_64FC3: inpaint ( src, mask, dst, algorithmType ); break; case CV_64FC4: inpaint ( src, mask, dst, algorithmType ); break; default: CV_Error_( CV_StsNotImplemented, ("Unsupported source image format (=%d)", src.type()) ); break; } } }