imread函数原型
Mat imread( const String& filename, int flags = IMREAD_COLOR );
- 返回值:Mat类型,返回读取的图像Mat对象,如果读取图像失败则返回一个空的Mat对象
- 参数1 filename:读取的图片文件名,可以写绝对路径或相对路径
- 参数2 flags:读取标记,默认值为IMREAD_COLOR,表示用什么颜色格式读取图片
可读取的图片格式:
- Windows bitmaps - \*.bmp, \*.dib (always supported)
- JPEG files - \*.jpeg, \*.jpg, \*.jpe (see the *Note* section)
- JPEG 2000 files - \*.jp2 (see the *Note* section)
- Portable Network Graphics - \*.png (see the *Note* section)
- WebP - \*.webp (see the *Note* section)
- Portable image format - \*.pbm, \*.pgm, \*.ppm \*.pxm, \*.pnm (always supported)
- PFM files - \*.pfm (see the *Note* section)
- Sun rasters - \*.sr, \*.ras (always supported)
- TIFF files - \*.tiff, \*.tif (see the *Note* section)
- OpenEXR Image files - \*.exr (see the *Note* section)
- Radiance HDR - \*.hdr, \*.pic (always supported)
- Raster and Vector geospatial data supported by GDAL (see the *Note* section)
- IMREAD_UNCHANGED = -1;按原样返回加载的图像
- IMREAD_GRAYSCALE = 0;将图像转换为单通道灰度图像加载
- IMREAD_COLOR = 1;将图像转换为BGR彩色图像加载
- IMREAD_ANYDEPTH = 2;具有相应深度时返回16位/32位图像,否则返回8位图像
- IMREAD_ANYCOLOR = 4;以任何可能的颜色形式读取图像
- IMREAD_LOAD_GDAL = 8;使用gdal驱动程序加载图像
- IMREAD_REDUCED_GRAYSCALE_2 = 16;将图像转换为单通道灰度图像并且图像尺寸减小二分之一
- IMREAD_REDUCED_COLOR_2 = 17;将图像转换为3通道BGR彩色图像并且图像尺寸减小二分之一
- IMREAD_REDUCED_GRAYSCALE_4 = 32;将图像转换为单通道灰度图像并且图像尺寸减小四分之一
- IMREAD_REDUCED_COLOR_4 = 33;将图像转换为3通道BGR彩色图像并且图像尺寸减小四分之一
- IMREAD_REDUCED_GRAYSCALE_8 = 64;将图像转换为单通道灰度图像并且图像尺寸减小八分之一
- IMREAD_REDUCED_COLOR_8 = 65;将图像转换为3通道BGR彩色图像并且图像尺寸减小八分之一
- IMREAD_IGNORE_ORIENTATION = 128;设置了之后部根据EXIF方向标志来旋转图像
代码示例
#include <opencv2/opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
int main()
{
Mat src = imread("E:/opencv_source/opencv_tutorial_data-master/images/dog.jpg",IMREAD_COLOR);
if (src.empty())
{
printf("check your picture");
return -1;
}
imshow("input", src);
waitKey(0);
destroyAllWindows();
return 0;
}