网上查了一下,OpenCV读取图片之后Mat默认的颜色通道都说是BGR,有点不信,试了一下,先用PS做一张纯色的图片,还有颜色的RGB值
然后用OpenCV读取图片之后读取RGB值逐一显示出来:
1 // OpenCV_default_color_channel.cpp : 定义控制台应用程序的入口点。 2 // 3 4 5 #include "opencv2/core/core.hpp" 6 #include "opencv2/highgui/highgui.hpp" 7 #include "opencv2/imgproc/imgproc.hpp" 8 #include "opencv2/imgproc/imgproc_c.h" 9 #include <iostream> 10 #include <string> 11 12 using namespace cv; 13 using namespace std; 14 15 16 int main(int argc, char* argv[]) 17 { 18 Mat src; 19 src = imread("pic.jpg"); 20 21 int channel1 = 0, channel2 = 0, channel3 = 0; 22 channel1 = ((uchar *)(src.data))[0]; 23 channel2 = ((uchar *)(src.data))[1]; 24 channel3 = ((uchar *)(src.data))[2]; 25 26 cout << "channel1:" << channel1 << endl; 27 cout << "channel2:" << channel2 << endl; 28 cout << "channel3:" << channel3 << endl; 29 30 imshow("pic", src); 31 32 waitKey(0); 33 return 0; 34 35 }
结果如下,还真是BGR的坑爹顺序:
时间: 2024-11-05 15:47:26