如何将R、G、B通道3附图merge为一幅彩色图

#include 
#include 
#include 
#include"opencv2/opencv.hpp"
using namespace std;
using namespace cv;

int main(int argc,char* argv[])
{
		
		Mat image=imread("逐帧人脸B_4*4_result_00.jpg");
		Size s=image.size();
		Mat result= Mat::zeros(s, CV_32FC3);


		Mat imageGreenChannel = imread("逐帧人脸G_4*4_result_00.jpg");
		Mat imageRedChannel = imread("逐帧人脸R_4*4_result_00.jpg");
		Mat imageBlueChannel = imread("逐帧人脸B_4*4_result_00.jpg");
		//这个函数将rgb转为单通道图像,这一步必不可少
		cvtColor(imageBlueChannel, imageBlueChannel, CV_BGR2GRAY); 
		cvtColor(imageGreenChannel, imageGreenChannel, CV_BGR2GRAY); 
		cvtColor(imageRedChannel, imageRedChannel, CV_BGR2GRAY);

		 vector mbgr(3); 
		 mbgr[0] = imageBlueChannel; 
		 mbgr[1] = imageGreenChannel; 
		 mbgr[2] = imageRedChannel; 
		 merge(mbgr, result);
		imshow("逐帧人脸彩色_4*4_result.jpg",result);
		imwrite("逐帧人脸彩色_4*4_result.jpg",result);
		waitKey(0);
		return 0;
}

你可能感兴趣的:(opencv)