How to read OpenCV imread pictures
How to read OpenCV imread pictures, I believe that many inexperienced people do not know what to do, so this article summarizes the causes of the problem and solutions, through this article I hope you can solve this problem.
Function prototype
CV_EXPORTS_W Mat imread (const String& filename, int flags = IMREAD_COLOR)
Parameter description
The first parameter is the picture path name, which is strongly recommended to use / as the split symbol of the directory, for example
The second parameter has the following value, indicating whether the pixel operation needs to be performed during the reading process. For example, a value of 0 indicates that the pixel is converted to a grayscale value during the reading process. The default parameter is 1, which means that the pixel of the original image is not changed.
Enum ImreadModes {
IMREAD_UNCHANGED =-1, / /! < If set, return the loaded p_w_picpath as is (with alpha channel, otherwise it gets cropped).
IMREAD_GRAYSCALE = 0, / /! < If set, always convert p_w_picpath to the single channel grayscale p_w_picpath.
IMREAD_COLOR = 1, / /! < If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath.
IMREAD_ANYDEPTH = 2, / /! < If set, return 16-bit/32-bit p_w_picpath when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, / /! < If set, the p_w_picpath is read in any possible color format.
IMREAD_LOAD_GDAL = 8, / /! < If set, use the gdal driver for loading the p_w_picpath.
IMREAD_REDUCED_GRAYSCALE_2 = 16, / /! < If set, always convert p_w_picpath to the single channel grayscale p_w_picpath and the p_w_picpath size reduced 1 Universe 2.
IMREAD_REDUCED_COLOR_2 = 17, / /! < If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath and the p_w_picpath size reduced 1 max 2.
IMREAD_REDUCED_GRAYSCALE_4 = 32, / /! < If set, always convert p_w_picpath to the single channel grayscale p_w_picpath and the p_w_picpath size reduced 1 Universe 4.
IMREAD_REDUCED_COLOR_4 = 33, / /! < If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath and the p_w_picpath size reduced 1 Universe 4.
IMREAD_REDUCED_GRAYSCALE_8 = 64, / /! < If set, always convert p_w_picpath to the single channel grayscale p_w_picpath and the p_w_picpath size reduced 1 Universe 8.
IMREAD_REDUCED_COLOR_8 = 65, / /! < If set, always convert p_w_picpath to the 3 channel BGR color p_w_picpath and the p_w_picpath size reduced 1 max 8.
IMREAD_IGNORE_ORIENTATION = 128 / /! < If set, do not rotate the p_w_picpath according to EXIF's orientation flag.
}
Examples
# include "opencv2/opencv.hpp"
Int main (int argc, char * argv [])
{
Cv::Mat srcImg = cv::imread ("F:/test2.png", 1)
Return 0
}
Note:
After the gray value of the image is processed, the histogram of the image will not be enhanced by default, otherwise an abnormal operation will occur.
Code
# include
# include
# include
Using namespace cv
Int main (int argc, char * argv [])
{
Mat p_w_picpath = imread ("D:/20170601092226.png", 0)
If (p_w_picpath.empty ())
{
Std::cout