From 6d5f7b72c0cede07c5e8450061e208585d48b875 Mon Sep 17 00:00:00 2001 From: Suleyman TURKMEN Date: Wed, 12 Sep 2018 17:34:32 +0300 Subject: [PATCH] Update seamless_cloning.cpp --- modules/photo/src/seamless_cloning.cpp | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/modules/photo/src/seamless_cloning.cpp b/modules/photo/src/seamless_cloning.cpp index e5fcd094fb..629c56fc1e 100644 --- a/modules/photo/src/seamless_cloning.cpp +++ b/modules/photo/src/seamless_cloning.cpp @@ -54,20 +54,27 @@ void cv::seamlessClone(InputArray _src, InputArray _dst, InputArray _mask, Point const Mat src = _src.getMat(); const Mat dest = _dst.getMat(); const Mat mask = _mask.getMat(); - _blend.create(dest.size(), CV_8UC3); + dest.copyTo(_blend); Mat blend = _blend.getMat(); - dest.copyTo(blend); - - int minx = INT_MAX, miny = INT_MAX, maxx = INT_MIN, maxy = INT_MIN; - int h = mask.size().height; - int w = mask.size().width; Mat gray; if(mask.channels() == 3) cvtColor(mask, gray, COLOR_BGR2GRAY ); else - mask.copyTo(gray); + { + if (mask.empty()) + gray = Mat(src.rows, src.cols, CV_8UC1, Scalar(255)); + else + mask.copyTo(gray); + } + + Mat gray_inner = gray(Rect(1, 1, gray.cols - 2, gray.rows - 2)); + copyMakeBorder(gray_inner, gray, 1, 1, 1, 1, BORDER_ISOLATED | BORDER_CONSTANT, Scalar(0)); + + int minx = INT_MAX, miny = INT_MAX, maxx = INT_MIN, maxy = INT_MIN; + int h = gray.size().height; + int w = gray.size().width; for(int i=0;i