From ed3d2cd12264f6ed7eee96b01ef45bfcec780177 Mon Sep 17 00:00:00 2001 From: stalin18 Date: Sun, 18 Sep 2016 18:41:02 +0530 Subject: [PATCH] fixed unnecessary reconstruction in seamlessclone fixed unnecessary reconstruction in seamlessclone by using only the required rectangular area in input images --- modules/photo/src/seamless_cloning.cpp | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/modules/photo/src/seamless_cloning.cpp b/modules/photo/src/seamless_cloning.cpp index ed02f8cf92..3e18c7cb08 100644 --- a/modules/photo/src/seamless_cloning.cpp +++ b/modules/photo/src/seamless_cloning.cpp @@ -56,15 +56,13 @@ void cv::seamlessClone(InputArray _src, InputArray _dst, InputArray _mask, Point const Mat mask = _mask.getMat(); _blend.create(dest.size(), CV_8UC3); 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 = Mat(mask.size(),CV_8UC1); - Mat dst_mask = Mat::zeros(dest.size(),CV_8UC1); - Mat cs_mask = Mat::zeros(src.size(),CV_8UC3); - Mat cd_mask = Mat::zeros(dest.size(),CV_8UC3); if(mask.channels() == 3) cvtColor(mask, gray, COLOR_BGR2GRAY ); @@ -100,19 +98,16 @@ void cv::seamlessClone(InputArray _src, InputArray _dst, InputArray _mask, Point Rect roi_d(minyd,minxd,leny,lenx); Rect roi_s(miny,minx,leny,lenx); - Mat destinationROI = dst_mask(roi_d); - Mat sourceROI = cs_mask(roi_s); + Mat destinationROI = dest(roi_d).clone(); - gray(roi_s).copyTo(destinationROI); + Mat sourceROI = Mat::zeros(leny, lenx, src.type()); src(roi_s).copyTo(sourceROI,gray(roi_s)); - src(roi_s).copyTo(patch, gray(roi_s)); - - destinationROI = cd_mask(roi_d); - cs_mask(roi_s).copyTo(destinationROI); + Mat maskROI = gray(roi_s); + Mat recoveredROI = blend(roi_d); Cloning obj; - obj.normalClone(dest,cd_mask,dst_mask,blend,flags); + obj.normalClone(destinationROI,sourceROI,maskROI,recoveredROI,flags); }