#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; //定义一个Mat向量容器保存拆分后的数据 vector<Mat> channels; //判断文件加载是否正确 assert(srcImage.data!=NULL); namedWindow("image",CV_WINDOW_AUTOSIZE); namedWindow("mergeImage",CV_WINDOW_AUTOSIZE); //通道的拆分 split(srcImage,channels); //提取蓝色通道的数据 imageBlue = channels.at(0); //提取绿色通道的数据 imageGreen = channels.at(1); //提取红色通道的数据 imageRed = channels.at(2); imshow("image",imageBlue); //对拆分的通道数据合并 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; //定义一个Mat向量容器保存拆分后的数据 vector<Mat> channels; //判断文件加载是否正确 assert(srcImage.data!=NULL && logoImage.data!=NULL); //namedWindow("image",CV_WINDOW_AUTOSIZE); namedWindow("mergeImage",CV_WINDOW_AUTOSIZE); //通道的拆分 split(srcImage,channels); //提取蓝色通道的数据 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))); //对拆分的通道数据合并 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; }
时间: 2024-09-15 04:13:30