<opencv>第三课 颜色空间

1
2
void cv::cvtColor(InputArray src, OutputArray dst, int code, int dstCn = 0)

将图像从一种颜色空间转换为另一种颜色空间。该函数将输入图像从一种颜色空间转换为另一种颜色空间。在从 RGB 颜色空间转换的情况下,应明确指定通道的顺序(RGB 或 BGR)。man请注意,OpenCV 中的默认颜色格式通常称为 RGB,但实际上是 BGR(字节反转)。因此,标准(24 位)彩色图像中的第一个字节将是 8 位蓝色分量,第二个字节将是绿色,第三个字节将是红色。 然后第四、第五和第六个字节将是第二个像素(蓝色,然后是绿色,然后是红色),依此类推。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
#include <opencv2/imgproc.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
    string path = "../lesson1_pictureRead/img1.jpg";
    Mat img = imread(path);
    Mat imgGray;
    cvtColor(img, imgGray, COLOR_BGR2GRAY); //灰度化
    imshow("Image", img);
    imshow("ImageGray", imgGray);
    waitKey(0);
  return 0;
}


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

<opencv>第三课 颜色空间
https://hermione20.github.io/2024/10/14/第3课 颜色空间/
作者
TC
发布于
2024年10月14日
许可协议