OpenCV 中的split函数和merge函数 及示例_opencv split_zqx951102的博客-CSDN博客
#include <QApplication>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
#include <QDebug>
using namespace cv;
using namespace std;int main(int argc, char *argv[])
{
QApplication a(argc, argv);
string path="D:\\Qt\\Qt5Book\\Qt5.14\\opencv\\try1\\widget\\5.png";Mat img = imread(path);//创建图像
vector<Mat> channels;
split(img,channels);//BGR三个通道分离vector<Mat> mbgr(3);
Mat bk1(img.size(),CV_8UC1,Scalar(0));//CV_8UC1:CV_+(位数)+(数据类型)+(通道数)
//这里是8位+unsigned char型+1个通道
Mat imageB(img.size(),CV_8UC3);//8位+unsigned char型+3个通道
/*
mbgr[0]=channels[0];
mbgr[1]=bk1;
mbgr[2]=bk1;
*///蓝色通道
/*
mbgr[0]=bk1;
mbgr[1]=channels[1];
mbgr[2]=bk1;
*///绿色通道
/*
mbgr[0]=bk1;
mbgr[1]=bk1;
mbgr[2]=channels[2];
*///红色通道
mbgr[0]=channels[0];
mbgr[1]=channels[1];
mbgr[2]=channels[2];merge(mbgr,imageB);
//这里把3个通道进行了合并。
imshow("imageB",imageB);return a.exec();
}