欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

彩色图像RGB通道的分离、合并

程序员文章站 2022-04-01 09:29:09
...

#include <iostream>
#include "cv.h"
#include "highgui.h"

using namespace std;
using namespace cv;

int main(int argc,char* argv[])
{
	Mat img = imread("lena.jpg"/*,CV_LOAD_IMAGE_COLOR*/);
	Mat channel[3];
	split(img,channel);
	imshow("original",img);
	imshow("B",channel[0]);
	imshow("G",channel[1]);
	imshow("R",channel[2]);

	//set blue channel to 0
	channel[0] = Mat::zeros(img.rows,img.cols,CV_8UC1);
	//merge red and green channels
	merge(channel,3,img);
	imshow("R_G_merge",img);

	waitKey(0);
	return 1;
}

 

对摄像头摄入视频帧的RGB彩色通道分离

Mat frame;
vector<Mat> rgb;

cap >> frame;
imshow("original", frame);
split(frame, rgb);

imshow("red", rgb.at(2));
imshow("green", rgb.at(1));
imshow("blue", rgb.at(0));

 

From: http://lib.csdn.net/article/opencv/25901