学OpenCV

================================================

颜色模型之间可以互相转换

 

================================================

示例代码

 1 #include <iostream>
 2 
 3 #include <opencv2/opencv.hpp>
 4 #include <opencv2/core/utils/logger.hpp>
 5 
 6 
 7 void Test1()
 8 {
 9     cv::Mat img;
10     img = cv::imread(R"(C:\testNoGit\learnOpenCV4-master\data\lena.png)");
11     if (img.empty())
12     {
13         std::cout << "请确认图像文件名是否正确" << std::endl;
14         return ;
15     }
16 
17     cv::Mat gray, hsv, yuv, lab, img32;
18     img.convertTo(img32,CV_32F,1,0);//y=kx+b 这里的参数3是k,参数4是b
19     
20     cv::cvtColor(img, gray, cv::COLOR_BGR2GRAY);
21     cv::cvtColor(img, hsv, cv::COLOR_BGR2HSV);
22     cv::cvtColor(img, yuv, cv::COLOR_BGR2YUV);
23     cv::cvtColor(img, lab, cv::COLOR_BGR2Lab);
24 
25     cv::imshow("img", img);
26     cv::imshow("img32", img32);
27     cv::imshow("gray", gray);
28     cv::imshow("hsv", hsv);
29     cv::imshow("yuv", yuv);
30     cv::imshow("lab", lab);
31 }
32 
33 int main()
34 {
35     cv::utils::logging::setLogLevel(cv::utils::logging::LOG_LEVEL_ERROR);
36     
37     Test1();
38 
39     cv::waitKey(0);
40 
41     return 0;
42 }

 

================================================

效果展示