融合时类型要一致,所以读取图像时使用灰度图像。
int base::splitChannel( string strFilePath, string strTempFilePath, QLabel* labelImage, BGR channel )
{
vector<Mat> channels;
Mat matChannel;
Mat roi;
Mat matSource = imread(strFilePath);
if (!matSource.data)
{
return(-1);
}
//读取灰度图像
Mat matTemp = imread(strTempFilePath, CV_LOAD_IMAGE_GRAYSCALE);
if (!matTemp.data)
{
return(-1);
}
//分离原图颜色通道
split(matSource, channels);
matChannel = channels.at(channel);
//取分离后的区域混合
roi = matChannel(Rect(330, 0, matTemp.cols, matTemp.rows));
addWeighted(roi, 0, matTemp, 1, 0, roi);
//重新合并
merge(channels, matSource);
loadImg(matSource, labelImage);
}