Merge pull request #9654 from savuor:seamlessclone

pull/9658/merge
Vadim Pisarevsky 7 years ago
commit 92deccbf41
  1. 19
      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(); const Mat mask = _mask.getMat();
_blend.create(dest.size(), CV_8UC3); _blend.create(dest.size(), CV_8UC3);
Mat blend = _blend.getMat(); Mat blend = _blend.getMat();
dest.copyTo(blend);
int minx = INT_MAX, miny = INT_MAX, maxx = INT_MIN, maxy = INT_MIN; int minx = INT_MAX, miny = INT_MAX, maxx = INT_MIN, maxy = INT_MIN;
int h = mask.size().height; int h = mask.size().height;
int w = mask.size().width; int w = mask.size().width;
Mat gray = Mat(mask.size(),CV_8UC1); 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) if(mask.channels() == 3)
cvtColor(mask, gray, COLOR_BGR2GRAY ); cvtColor(mask, gray, COLOR_BGR2GRAY );
@ -88,8 +86,6 @@ void cv::seamlessClone(InputArray _src, InputArray _dst, InputArray _mask, Point
int lenx = maxx - minx; int lenx = maxx - minx;
int leny = maxy - miny; int leny = maxy - miny;
Mat patch = Mat::zeros(Size(leny, lenx), CV_8UC3);
int minxd = p.y - lenx/2; int minxd = p.y - lenx/2;
int maxxd = p.y + lenx/2; int maxxd = p.y + lenx/2;
int minyd = p.x - leny/2; int minyd = p.x - leny/2;
@ -100,19 +96,16 @@ void cv::seamlessClone(InputArray _src, InputArray _dst, InputArray _mask, Point
Rect roi_d(minyd,minxd,leny,lenx); Rect roi_d(minyd,minxd,leny,lenx);
Rect roi_s(miny,minx,leny,lenx); Rect roi_s(miny,minx,leny,lenx);
Mat destinationROI = dst_mask(roi_d); Mat destinationROI = dest(roi_d).clone();
Mat sourceROI = cs_mask(roi_s);
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(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; Cloning obj;
obj.normalClone(dest,cd_mask,dst_mask,blend,flags); obj.normalClone(destinationROI,sourceROI,maskROI,recoveredROI,flags);
} }

Loading…
Cancel
Save