Disclaimer: This article is a blogger original article, shall not be reproduced without the bloggers allowed. https://blog.csdn.net/withlonger/article/details/81191967
Today started learning opencv, simply record what the learning process. Learning opencv on the display picture started. Save a picture with the data structure Mat, read a picture with the function imread. Defined in detail below, a reference to the image path, two parameters for the enumeration constant, enumeration constant may take the value of 13.
Mat imread( const String& filename, int flags = IMREAD_COLOR );
//! Imread flags
enum ImreadModes {
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image.
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.
IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/8.
IMREAD_REDUCED_COLOR_8 = 65, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8.
IMREAD_IGNORE_ORIENTATION = 128 //!< If set, do not rotate the image according to EXIF's orientation flag.
};
Display a picture, with the function imshow. Opencv function in the source code statement is as follows, InputArray can pass a type of Mat.
void imshow(const String& winname, InputArray mat);
The following is an example of usage.
#include <iostream>
#include <opencv2/opencv.hpp>
using namespace std;
using namespace cv;
void main() {
//读入一张图片,一参为图片的绝对路径,二参为枚举常量,有 IMREAD_COLOR、IMREAD_GRAYSCALE等
Mat srcImg = imread("d:/data/test.png",IMREAD_LOAD_GDAL);
imshow("源图像", srcImg);
waitKey();//暂停窗口
}