#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");
for (int i = 0; i < 3; i++)
{
Mat bgr(img.rows, img.cols, CV_8UC3, Scalar(0, 0, 0));
Mat temp(img.rows, img.cols, CV_8UC1);
Mat out[] = { bgr };
int from_to[] = { i,i };
mixChannels(&img, 1, out, 1, from_to,1);//
//获得其中一个通道的数据进行分析
imshow("1 channel", bgr);
waitKey();
}
#include<opencv2/imgproc/imgproc.hpp>
#include<iostream>
using namespace std;
using namespace cv;
int main()
{
Mat img;
img = imread("timg.jpg");
for (int i = 0; i < 3; i++)
{
Mat bgr(img.rows, img.cols, CV_8UC3, Scalar(0, 0, 0));
Mat temp(img.rows, img.cols, CV_8UC1);
Mat out[] = { bgr };
int from_to[] = { i,i };
mixChannels(&img, 1, out, 1, from_to,1);//
//获得其中一个通道的数据进行分析
imshow("1 channel", bgr);
waitKey();
}
}
上面这种方法得到的每个通道都是彩色图像!而用split函数可以得到单通道的灰度图像。(OpenCV3.0; VS2017)
std::vector<Mat> channels;
Mat aChannels[3];
//src为要分离的Mat对象
split(src, aChannels); //利用数组分离
split(src, channels); //利用vector对象分离
imshow("B", channels[0]);
imshow("aB", aChannels[0]);
imshow("G", channels[1]);
imshow("aG", aChannels[1]);
imshow("R", channels[2]);
imshow("aR", aChannels[2]);
转自:
https://blog.csdn.net/u012283902/article/details/55195073
https://blog.csdn.net/huangwumanyan/article/details/52809671