- #include<opencv2/opencv.hpp>
- #include<iostream>
- #include<cassert>
- #include<vector>
- using namespace cv;
- using namespace std;
- int main()
- {
- Mat srcImage=imread("e:/huangshan.jpg");
- Mat imageBlue,imageGreen,imageRed;
- Mat mergeImage;
- //定義一個(gè)Mat向量容器保存拆分后的數(shù)據(jù)
- vector<Mat> channels;
-
- //判斷文件加載是否正確
- assert(srcImage.data!=NULL);
- namedWindow("image",CV_WINDOW_AUTOSIZE);
- namedWindow("mergeImage",CV_WINDOW_AUTOSIZE);
-
- //通道的拆分
- split(srcImage,channels);
-
- //提取藍(lán)色通道的數(shù)據(jù)
- imageBlue = channels.at(0);
-
- //提取綠色通道的數(shù)據(jù)
- imageGreen = channels.at(1);
-
- //提取紅色通道的數(shù)據(jù)
- imageRed = channels.at(2);
- imshow("image",imageBlue);
-
- //對(duì)拆分的通道數(shù)據(jù)合并
- merge(channels,mergeImage);
- imshow("mergeImage",mergeImage);
- waitKey();
- system("pause");
- return 0;
- }
- #include<opencv2/opencv.hpp>
- #include<iostream>
- #include<cassert>
- #include<vector>
- using namespace cv;
- using namespace std;
- int main()
- {
- Mat srcImage=imread("e:/jiansheng.jpg");
- Mat logoImage = imread("e:/timu.jpg",0);
- Mat imageBlue,imageGreen,imageRed;
- Mat mergeImage;
- //定義一個(gè)Mat向量容器保存拆分后的數(shù)據(jù)
- vector<Mat> channels;
-
- //判斷文件加載是否正確
- assert(srcImage.data!=NULL && logoImage.data!=NULL);
- //namedWindow("image",CV_WINDOW_AUTOSIZE);
- namedWindow("mergeImage",CV_WINDOW_AUTOSIZE);
-
- //通道的拆分
- split(srcImage,channels);
-
- //提取藍(lán)色通道的數(shù)據(jù)
- imageBlue = channels.at(1);
- addWeighted(imageBlue(Rect(0,0,logoImage.cols,logoImage.rows)),0.5,logoImage,0.5,0.,imageBlue(Rect(0,0,logoImage.cols,logoImage.rows)));
-
-
- //對(duì)拆分的通道數(shù)據(jù)合并
- merge(channels,mergeImage);
- imshow("mergeImage",mergeImage);
- waitKey();
- system("pause");
- return 0;
- }
- #include<opencv2/opencv.hpp>
- #include<iostream>
- #include<vector>
- using namespace std;
- using namespace cv;
- int main()
- {
- Mat img = imread("f:/huang.jpg");
- namedWindow("image",WINDOW_AUTOSIZE);
- imshow("image",img);
- Mat gray;
- cvtColor(img,gray,CV_RGB2GRAY);
- namedWindow("gray",WINDOW_AUTOSIZE);
- imshow("gray",gray);
- Mat mimg = imread("f:/mei.jpeg");
- namedWindow("mei",WINDOW_AUTOSIZE);
- resize(mimg,mimg,Size(img.cols,img.rows));
- addWeighted(mimg,0.2,img,0.9,0.,mimg);
- imshow("mei",mimg);
- vector<Mat> channels;
- split(img,channels);
- vector<Mat>::iterator it = channels.begin();
- char str[][20]={"blue","green","red"};
- int i=0;
- for(;it!=channels.end();++it,++i)
- {
-
- namedWindow(str[i],WINDOW_AUTOSIZE);
- imshow(str[i],*it);
- }
- waitKey();
- return 0;
- }
|