分离颜色通道、多通道图像混合
一、通道分离:split()函数
1 #include<opencv2/opencv.hpp> 2 #include<iostream> 3 #include<vector> 4 using namespace cv; 5 using namespace std; 6 7 bool ROI_AddImage(); 8 bool LinearBlending(); 9 10 11 int main(int argc, char** argv) { 12 //Mat image1= imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\05.jpg"); 13 //Mat image2 = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\08.jpg"); 14 system("color 5E"); 15 if (ROI_AddImage() && LinearBlending() ) { 16 cout << endl << "运行成功,得出了你需要的图像~:"; 17 } 18 waitKey(0); 19 return 0; 20 21 22 } 23 24 bool ROI_AddImage() { //利用感兴趣的区域ROI实现图像叠加 25 //读入图像 26 Mat srcImage1 = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\05.jpg"); 27 Mat logoImage = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\001.jpg"); 28 29 //定义一个Match类型并给其设定ROI区域 30 Mat imageROI = srcImage1(Rect(srcImage1.cols-logoImage.cols, srcImage1.rows-logoImage.rows,logoImage.cols,logoImage.rows)); 31 32 //加载掩模 33 Mat mask = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\001.jpg",0); 34 35 //将掩模复制到ROI 36 logoImage.copyTo(imageROI,mask); 37 38 //显示结果 39 namedWindow("hah"); 40 imshow("hah",srcImage1); 41 42 return true; 43 } 44 45 bool LinearBlending() { //利用addWeighted()函数实现图像线性混合 46 double alphaValue = 0.5; 47 double betaValue; 48 Mat srcImage2, srcImage3, dstImage; 49 50 //读取图像(两幅图类型和尺寸相同) 51 srcImage2 = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\05.jpg"); 52 srcImage3 = imread("C:\\Users\\Nelsoner\\Desktop\\Camera Roll\\08.jpg"); 53 54 //进行图像混合加权操作 55 betaValue = (1.0 - alphaValue); 56 addWeighted(srcImage2, alphaValue, srcImage3, betaValue,0.0,dstImage); 57 58 namedWindow("heh"); 59 imshow("heh",dstImage); 60 61 return true; 62 }