opencv--函数imread()
目录:
1,函数用法
2,参数说明
3,参数filename,支持的文件格式
4,参数flags
5,notes:
1,函数用法imread()
retval = cv.imread( filename[, flags] )
从文件加载图像。
该函数imread从指定的文件加载图像并返回它。如果无法读取图像(由于缺少文件,权限不正确,格式不受支持或格式无效),该函数将返回一个空矩阵(Mat :: data == NULL)。
2,参数说明:
filename 要加载的文件名
flags 可以接收的 cv :: ImreadModes值的(详见下面章节)
3,参数filename,支持的文件格式
file,图片文件 支持以下文件格式:
- Windows bitmaps - *.bmp, *.dib (always supported)
- JPEG files - *.jpeg, *.jpg, *.jpe (see the Notes section)
- JPEG 2000 files - *.jp2 (see the Notes section)
- Portable Network Graphics - *.png (see the Notes section)
- WebP - *.webp (see the Notes section)
- Portable image format - *.pbm, *.pgm, *.ppm *.pxm, *.pnm (always supported)
- Sun rasters - *.sr, *.ras (always supported)
- TIFF files - *.tiff, *.tif (see the Notes section)
- OpenEXR Image files - *.exr (see the Notes section)
- Radiance HDR - *.hdr, *.pic (always supported)
- Raster and Vector geospatial data supported by Gdal (see the Notes section)
4,参数flags
flags的值:传入不同的参数,产生不同的效果
| IMREAD_UNCHANGED
Python: cv.IMREAD_UNCHANGED
|
If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). 如果设置,则按原样返回加载的图像(带有Alpha通道,否则将被裁剪) |
| IMREAD_GRAYSCALE
Python: cv.IMREAD_GRAYSCALE
|
If set, always convert image to the single channel grayscale image. 如果设置,请始终将图像转换为单通道灰度图像。 |
| IMREAD_COLOR
Python: cv.IMREAD_COLOR
|
If set, always convert image to the 3 channel BGR color image. 如果设置,请始终将图像转换为3通道BGR彩色图像。 |
| IMREAD_ANYDEPTH
Python: cv.IMREAD_ANYDEPTH
|
If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit. 如果设置,则当输入具有相应的深度时返回16位/ 32位图像,否则将其转换为8位。 |
| IMREAD_ANYCOLOR
Python: cv.IMREAD_ANYCOLOR
|
If set, the image is read in any possible color format. 如果设置,将以任何可能的颜色格式读取图像。 |
| IMREAD_LOAD_GDAL
Python: cv.IMREAD_LOAD_GDAL
|
If set, use the gdal driver for loading the image. 如果已设置,请使用Gdal驱动程序加载图像 |
| IMREAD_REDUCED_GRAYSCALE_2
Python: cv.IMREAD_REDUCED_GRAYSCALE_2
|
If set, always convert image to the single channel grayscale image and the image size reduced 1/2. 如果设置,则始终将图像转换为单通道灰度图像,并且图像尺寸减小1/2。 |
| IMREAD_REDUCED_COLOR_2
Python: cv.IMREAD_REDUCED_COLOR_2
|
If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2. 如果设置,请始终将图像转换为3通道BGR彩色图像,并且图像尺寸减小1/2。 |
| IMREAD_REDUCED_GRAYSCALE_4
Python: cv.IMREAD_REDUCED_GRAYSCALE_4
|
If set, always convert image to the single channel grayscale image and the image size reduced 1/4. 如果设置,则始终将图像转换为单通道灰度图像,并且图像尺寸减小1/4。 |
| IMREAD_REDUCED_COLOR_4
Python: cv.IMREAD_REDUCED_COLOR_4
|
If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4. 如果设置,请始终将图像转换为3通道BGR彩色图像,并且图像尺寸减小1/4。 |
| IMREAD_REDUCED_GRAYSCALE_8
Python: cv.IMREAD_REDUCED_GRAYSCALE_8
|
If set, always convert image to the single channel grayscale image and the image size reduced 1/8. 如果设置,请始终将图像转换为单通道灰度图像,并且图像尺寸减小1/8。 |
| IMREAD_REDUCED_COLOR_8
Python: cv.IMREAD_REDUCED_COLOR_8
|
If set, always convert image to the 3 channel BGR color image and the image size reduced 1/8. 如果设置,请始终将图像转换为3通道BGR彩色图像,并且图像尺寸减小1/8。 |
| IMREAD_IGNORE_ORIENTATION
Python: cv.IMREAD_IGNORE_ORIENTATION
|
If set, do not rotate the image according to EXIF's orientation flag. 如果已设置,请不要根据EXIF的方向标志旋转图像。 |
5,notes:
该功能通过内容而不是文件扩展名确定图像的类型。
在彩色图像的情况下,解码图像将具有以B G R顺序存储的通道。
在Microsoft
Windows * OS和MacOSX
*上,默认情况下使用OpenCV映像附带的编解码器(libjpeg,libpng,libtiff和libjasper)。因此,OpenCV始终可以读取JPEG,PNG和TIFF。在MacOSX上,还可以选择使用本机MacOSX图像读取器。但是请注意,由于MacOSX中嵌入了色彩管理,当前这些本机图像加载器会为图像提供不同的像素值。
在Linux
*,BSD风格和其他类似Unix的开源操作系统上,OpenCV会寻找OS映像随附的编解码器。安装相关的软件包(不要忘记在Debian
*和Ubuntu *中忘记开发文件,例如“
libjpeg-dev”)以获得编码解码器支持或在CMake中打开OPENCV_BUILD_3RDPARTY_LIBS标志。
如果您在CMake中将WITH_GDAL标志设置为true,并且将IMREAD_LOAD_GDAL设置为加载图像,则将使用GDAL驱动程序以通过支持以下格式来解码图像:Raster,Vector。
如果在图像文件中嵌入了EXIF信息,则将考虑EXIF方向,因此,除非传递了标志IMREAD_IGNORE_ORIENTATION,否则图像将相应地旋转。
参考链接
https://docs.opencv.org/3.4.1/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56
https://docs.opencv.org/3.4.1/d4/da8/group__imgcodecs.html#ga61d9b0126a3e57d9277ac48327799c80
浙公网安备 33010602011771号