From 0972a2d758924f53c7fb459f7cd7ee9cf762a771 Mon Sep 17 00:00:00 2001 From: siddharth Date: Thu, 29 May 2014 10:17:39 +0530 Subject: [PATCH] Fixed mixed cloning bug --- modules/photo/src/seamless_cloning.hpp | 33 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/modules/photo/src/seamless_cloning.hpp b/modules/photo/src/seamless_cloning.hpp index 143d550894..669be9f089 100644 --- a/modules/photo/src/seamless_cloning.hpp +++ b/modules/photo/src/seamless_cloning.hpp @@ -455,6 +455,8 @@ void Cloning::normal_clone(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, int num) { int w = I.size().width; int h = I.size().height; + int channel = I.channels(); + initialization(I,mask,wmask); @@ -466,20 +468,33 @@ void Cloning::normal_clone(Mat &I, Mat &mask, Mat &wmask, Mat &cloned, int num) } else if(num == 2) { + for(int i=0;i < h; i++) - for(int j=0; j < w; j++) + { + for(int j=0; j < w; j++) { - if(abs(sgx.at(i,j) - sgy.at(i,j)) > abs(grx.at(i,j) - gry.at(i,j))) + for(int c=0;c(i,j) = sgx.at(i,j) * smask.at(i,j); - sry32.at(i,j) = sgy.at(i,j) * smask.at(i,j); - } - else - { - srx32.at(i,j) = grx.at(i,j) * smask.at(i,j); - sry32.at(i,j) = gry.at(i,j) * smask.at(i,j); + if(abs(sgx.at(i,j*channel+c) - sgy.at(i,j*channel+c)) > + abs(grx.at(i,j*channel+c) - gry.at(i,j*channel+c))) + { + + srx32.at(i,j*channel+c) = sgx.at(i,j*channel+c) + * smask.at(i,j); + sry32.at(i,j*channel+c) = sgy.at(i,j*channel+c) + * smask.at(i,j); + } + else + { + srx32.at(i,j*channel+c) = grx.at(i,j*channel+c) + * smask.at(i,j); + sry32.at(i,j*channel+c) = gry.at(i,j*channel+c) + * smask.at(i,j); + } } } + } + } else if(num == 3) {