1. Image reading: imread ()
Mat imread(const string& ?lename, int ?ags=1 )
Parameter introduction:
Filename: Name of the file to be loaded.
Flags: Specifies the color type of the loaded image ). The value of this flag can be:
--Cv_load_image_anydepth: If this flag is set, if the image is a 16-bit or 32-bit depth image, the corresponding depth image is returned; otherwise, the image is converted to an 8-bit depth image and then returned.
--Cv_load_image_color: If this flag is set, the image is always converted to a color image.
--Cv_load_image_grayscale: If this flag is set, the image is always converted to a grayscale image.
Of course, we can also choose not to use these three flags, as long as they are Integer Variables. However, the values must follow the following rules:
Flags> 0: Returns a 3-channel color image. Note: In this implementation, the output image is not loaded into the alpha channel. If you need to use the alpha channel, use a negative value.
Flags = 0:Returns a grayscale image.
Flags <0: Returns an image in its own form (with an alpha channel ).
2. Image Display: imshow ()
void imshow(const string& winname, InputArray mat)
Parameter introduction:
Winname:Display the window name of the image.
MAT:The image to be displayed.
3. program example
The following code reads images in three different forms and displays them.
1 #include "stdafx.h" 2 #include <opencv2\highgui\highgui.hpp> 3 #include <opencv2\core\core.hpp> 4 5 using namespace cv; 6 7 8 int _tmain(int argc, _TCHAR* argv[]) 9 {10 Mat img1 = imread("D:/Media/Image/girl03.jpg", -1);11 if (!img1.empty()) imshow("Alpha Image", img1);12 13 Mat img2 = imread("D:/Media/Image/girl03.jpg", 0);14 if (!img2.empty()) imshow("Gray Image", img2);15 16 Mat img3 = imread("D:/Media/Image/girl03.jpg", 1);17 if (!img3.empty()) imshow("Color Image", img3);18 19 waitKey();20 21 return 0;22 }View code
The running result is as follows:
Flags at <0
Flags = 0
Flags> 0