学OpenCV

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

简单的看下读取图片时,各个参数的效果。

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

 1 #include <iostream>
 2 #include <opencv2/opencv.hpp>
 3 #include <opencv2/core/utils/logger.hpp>
 4 
 5 void Test1()
 6 {
 7     cv::Mat img =cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png");
 8     //cv::namedWindow("img");//可选
 9     cv::imshow("img", img);
10 
11     cv::Mat img2 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png",cv::ImreadModes::IMREAD_UNCHANGED);
12     cv::namedWindow("IMREAD_UNCHANGED");
13     cv::imshow("IMREAD_UNCHANGED", img2);
14 
15     cv::Mat img3 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_GRAYSCALE);
16     cv::namedWindow("IMREAD_GRAYSCALE");
17     cv::imshow("IMREAD_GRAYSCALE", img3);
18 
19     cv::Mat img4 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_COLOR);
20     cv::namedWindow("IMREAD_COLOR");
21     cv::imshow("IMREAD_COLOR", img4);
22 
23     cv::Mat img5 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_ANYDEPTH);
24     cv::namedWindow("IMREAD_ANYDEPTH");
25     cv::imshow("IMREAD_ANYDEPTH", img5);
26 
27     cv::Mat img6 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_ANYCOLOR);
28     cv::namedWindow("IMREAD_ANYCOLOR");
29     cv::imshow("IMREAD_ANYCOLOR", img6);
30 
31     cv::Mat img7 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_LOAD_GDAL);
32     cv::namedWindow("IMREAD_LOAD_GDAL");
33     cv::imshow("IMREAD_LOAD_GDAL", img7);
34 
35     cv::Mat img8 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_REDUCED_GRAYSCALE_2);
36     cv::namedWindow("IMREAD_REDUCED_GRAYSCALE_2");
37     cv::imshow("IMREAD_REDUCED_GRAYSCALE_2", img8);
38 
39     cv::Mat img9 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_REDUCED_GRAYSCALE_4);
40     cv::namedWindow("IMREAD_REDUCED_GRAYSCALE_4");
41     cv::imshow("IMREAD_REDUCED_GRAYSCALE_4", img9);
42 
43     cv::Mat img10 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_REDUCED_GRAYSCALE_8);
44     cv::namedWindow("IMREAD_REDUCED_GRAYSCALE_8");
45     cv::imshow("IMREAD_REDUCED_GRAYSCALE_8", img10);
46 
47     cv::Mat img11 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_REDUCED_COLOR_2);
48     cv::namedWindow("IMREAD_REDUCED_COLOR_2");
49     cv::imshow("IMREAD_REDUCED_COLOR_2", img11);
50 
51     cv::Mat img12 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_REDUCED_COLOR_4);
52     cv::namedWindow("IMREAD_REDUCED_COLOR_4");
53     cv::imshow("IMREAD_REDUCED_COLOR_4", img12);
54 
55     cv::Mat img13 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_REDUCED_COLOR_8);
56     cv::namedWindow("IMREAD_REDUCED_COLOR_8");
57     cv::imshow("IMREAD_REDUCED_COLOR_8", img13);
58 
59     cv::Mat img14 = cv::imread("C:/testNoGit/learnOpenCV4-master/data/lena.png", cv::ImreadModes::IMREAD_IGNORE_ORIENTATION);
60     cv::namedWindow("IMREAD_IGNORE_ORIENTATION");
61     cv::imshow("IMREAD_IGNORE_ORIENTATION", img14);
62 
63     cv::waitKey();
64 }
65 
66 int main()
67 {
68     //cv::utils::logging::setLogLevel(utils::logging::LOG_LEVEL_ERROR);
69     //Mat img;
70     //img = imread("C:/testNoGit/learnOpenCV4-master/data/lena.png");
71     //if (img.empty())
72     //{
73     //    cout << "请确认图像文件名是否正确" << endl;
74     //    return 1;
75     //}
76 
77     //imshow("test", img);
78     //waitKey(0);
79     Test1();
80 
81     return 0;
82 }