开发环境:VS2013+opencv3.0
#include<opencv2/opencv.hpp>
using namespace std;
using namespace cv;
int main()
{
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;
}
效果: