#include "stdafx.h"
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int _tmain(int argc, _TCHAR* argv[])
{
Mat InpImage=imread("test.jpg",-1);
Mat bgr[3];
Mat bgr_res[3];
for( int j = 0 ; j < 3; j++)
{
split(InpImage, bgr);
for (int i=0; i<3; ++i)
{
if (i != j )
bgr[i] = Mat::zeros(InpImage.size(), bgr[0].type());
}
merge(bgr, 3, bgr_res[j]);
}
imshow("b",bgr_res[0]);
imshow("g",bgr_res[1]);
imshow("r",bgr_res[2]);
imshow("原始图像",InpImage);
waitKey(0);
return 0;
}
注意:OpenCV通道分离是按照BGR顺序,waitKey();后面的要大写。