#include <opencv2/opencv.hpp>
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
//分离方法一,超麻烦,是官网的教程
Mat img;
img = imread("timg.jpg");
Mat R(img.rows, img.cols, CV_8UC3, Scalar(0, 0, 0));
Mat B(img.rows, img.cols, CV_8UC3, Scalar(0, 0, 0));
Mat G(img.rows, img.cols, CV_8UC3, Scalar(0, 0, 0));
Mat out[] = { B };
int from_to[] = { 0,0 };
mixChannels(&img, 1, out, 1, from_to, 1);
imshow("1 channel", B);
waitKey();
out[0] = G;
from_to[0] = 1;
from_to[1] = 1;
mixChannels(&img, 1, out, 1, from_to, 1);
imshow("1 channel", G);
waitKey();
out[0] = R;
from_to[0] = 2;
from_to[1] = 2;
mixChannels(&img, 1, out, 1, from_to, 1);
imshow("1 channel", R);
waitKey();
//方法2,CSDN上的
Mat imageROI,Combine;
vector channels;
// 把一个3通道图像转换成3个单通道图像
split(img, channels);//分离色彩通道
imageROI = channels.at(0);
imshow("c0", imageROI);
waitKey();
merge(channels, Combine);
imshow("Combine", Combine);
waitKey();
return 0;
}