这是源码以及运行结果,第一个是彩色原图,后面是分出来的3个通道
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
Mat img = imread("/home/su/code/opencv/g2.jfif", IMREAD_COLOR);
if (img.empty())
{
cout << -1 << "\n";
return -1;
}
imshow("bgr", img);
// Split the image into 3 single-channel images
Mat bgr[3];
split(img, bgr);
imshow("b", bgr[0]); // Blue channel
imshow("g", bgr[1]); // Green channel
imshow("r", bgr[2]); // Red channel
waitKey(0);
// Destroy all windows
destroyAllWindows();
return 0;
}
#include <opencv2/core/core.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main(int argc, char* argv[])
{
Mat img = imread("/home/su/code/opencv/g2.jfif", IMREAD_COLOR);
if (img.empty())
{
cout << -1 << "\n";
return -1;
}
imshow("bgr", img);
// Split the image into 3 single-channel images
Mat bgr[3];
split(img, bgr);
imshow("b", bgr[0]); // Blue channel
imshow("g", bgr[1]); // Green channel
imshow("r", bgr[2]); // Red channel
waitKey(0);
// Destroy all windows
destroyAllWindows();
return 0;
}