I'm a new comer in OpenCV, currently a strange issue in OpenCV make me in the trouble: Core function implement the formula:(base_color)/(blend_color)*255 which just want to eliminate the background color, code is likes this:
void clearBackground(Mat& input, Mat& output){
Mat gauss;
Mat dst = input.clone();
cv::GaussianBlur(input,gauss,Size(101,101),0);
vector<Mat> rgbChannels;
vector<Mat> gaussChannels;
vector<Mat> resultChannels;
split(input, rgbChannels);
split(gauss, gaussChannels);
for(int i =0; i<rgbChannels.size();i++){
Mat tempBase, tempMix,temp;
temp = rgbChannels[i]/gaussChannels[i]*255;
resultChannels.push_back(temp);
}
merge(resultChannels, output);
}
Code works as my expectation, however, when I just change the formula from
temp = rgbChannels[i]/gaussChannels[i]*255
into two steps just like:
temp = rgbChannels[i]/gaussChannels[I]
temp = temp * 255;
OR like this:
divide(rgbChannels[i], gaussChannels[i], temp);
multiply(temp,255, temp);
Then the result changed and would not as my expectation, in one word , I can not divide the formula: rgbChannels[i]/gaussChannels[i]*255 into two step as I expectation, no matter use the math operator or OpenCV built functions .
So the question is how can I divided the formula rgbChannels[i]/gaussChannels[i]*255 into two steps and do not impact the result .
Thanks @Ziri and @Andrey for the reminder, I just fix this issue and code just as below:
void clearBackground(Mat& input, Mat& output){ Mat gauss,temp;
input.convertTo(input,CV_32F);
cv::GaussianBlur(input,gauss,Size(101,101),0);
divide(input, gauss, temp);
multiply(temp,255, output);
output.convertTo(output,CV_8U);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.