fixed unnecessary reconstruction in seamlessclone

fixed unnecessary reconstruction in seamlessclone by using only the
required rectangular area in input images
pull/9654/head
stalin18 8 years ago committed by Rostislav Vasilikhin
parent 4435ec5f26
commit ed3d2cd122
  1. 17
      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);
}

Loading…
Cancel
Save