#include "opencv2/objdetect/objdetect.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
using namespace std;
using namespace cv;
int main()
{
Mat src = imread("image.png", 1);
namedWindow("src", 1);
imshow("src", src);
vector<Mat> rgbChannels(3);
split(src, rgbChannels);
namedWindow("R", 1);
imshow("R", rgbChannels[2]);
waitKey(0);
return 0;
}
.
我期待类似以下的内容:
为什么上面的代码没有显示红色 channel ?为什么它显示灰度图像?
如果图像被分成3个 channel ,每个矩阵应显示r、g和b颜色之一。不是这样吗?
最佳答案
您的代码是正确的;然而,OpenCV 将 channel 显示为灰度。 Mat
不保留有关数据来自“何处”的信息。换句话说,它不知道它是红色 channel ,因此当您调用 imshow
时,它会将其显示为单 channel 图像。
您可以做的是构建一个具有 2 个归零 channel 和您想要可视化的 channel 的空图像。
关于c++ - 为什么以下代码不显示图像的红色 channel ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51030592/