OpenCV学习笔记(六):imread介绍

内容来源:http://docs.opencv.org/3.0.0/d4/da8/group__imgcodecs.html#ga288b8b3da0892bd651fce07b3bbd3a56

Mat cv::imread ( const String &  filename,
    int  flags = IMREAD_COLOR 
  )    

Loads an image from a file.

Parameters
filename Name of file to be loaded.
flags Flag that can take values of cv::ImreadModes

The function imread loads an image from the specified file and returns it. If the image cannot be read (because of missing file, improper permissions, unsupported or invalid format), the function returns an empty matrix ( Mat::data==NULL ). Currently, the following file formats are supported:

翻译:imread函数从文件中加载图像并返回该图像。如果该图像不能被读取(由于文件丢失、权限不正确、不支持或非法的格式等原因),该函数返回一个空的矩阵(Mat中的data项为NULL)。现在已经支持一下的文件格式:

  • 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 (always supported)
  • Sun rasters - *.sr, *.ras (always supported)
  • TIFF files - *.tiff, *.tif (see the Notes section)
Note
  • The function determines the type of an image by the content, not by the file extension.
  • (该函数根据文件类容确定文件类型,而不是根据拓展名。)
  • On Microsoft Windows* OS and MacOSX*, the codecs shipped with an OpenCV image (libjpeg, libpng, libtiff, and libjasper) are used by default. So, OpenCV can always read JPEGs, PNGs, and TIFFs. On MacOSX, there is also an option to use native MacOSX image readers. But beware that currently these native image loaders give images with different pixel values because of the color management embedded into MacOSX.
  • (在Windows、Mac平台下,OpenCV默然激活了libjpeg, libpng, libtiff, and libjasper库。所以,OpenCV总是可以读取JPEGs, PNGs, and TIFFs格式的文件。在Mac的操作系统下,也可以使用MacOSX系统自身的图像读取函数。但是由于MacOSX的管理方式,现在这些系统自带的读取方式返回的像素点会有所不同。
  • On Linux*, BSD flavors and other Unix-like open-source operating systems, OpenCV looks for codecs supplied with an OS image. Install the relevant packages (do not forget the development files, for example, "libjpeg-dev", in Debian* and Ubuntu*) to get the codec support or turn on the OPENCV_BUILD_3RDPARTY_LIBS flag in CMake.
  • ()
Note
In the case of color images, the decoded images will have the channels stored in B G R order.
Examples:
demhist.cpp,  distrans.cpp,  edge.cpp,  ffilldemo.cpp,  fitellipse.cpp,  grabcut.cpp,  houghcircles.cpp,  houghlines.cpp,  lsd_lines.cpp, morphology2.cpp,  pca.cpp, and  watershed.cpp.

以上为官方文档对imread函数的说明,这里重点说一下flag参数cv::ImreadModes。

enum cv::ImreadModes

Imread flags.

Enumerator
IMREAD_UNCHANGED 

If set, return the loaded image as is (with alpha channel, otherwise it gets cropped).

IMREAD_GRAYSCALE 

If set, always convert image to the single channel grayscale image.

IMREAD_COLOR 

If set, always convert image to the 3 channel BGR color image.

IMREAD_ANYDEPTH 

If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.

IMREAD_ANYCOLOR 

If set, the image is read in any possible color format.

IMREAD_LOAD_GDAL 

If set, use the gdal driver for loading the image.

IMREAD_UNCHANGED :不进行转化,比如保存为了16位的图片,读取出来仍然为16位。

IMREAD_GRAYSCALE :进行转化为灰度图,比如保存为了16位的图片,读取出来为8位,类型为CV_8UC1。

IMREAD_COLOR :进行转化为三通道图像。

IMREAD_ANYDEPTH :如果图像深度为16位则读出为16位,32位则读出为32位,其余的转化为8位。

IMREAD_ANYCOLOR :

IMREAD_LOAD_GDAL :使用GDAL驱动读取文件,GDAL(Geospatial Data Abstraction Library)是一个在X/MIT许可协议下的开源栅格空间数据转换库。它利用抽象数据模型来表达所支持的各种文件格式。它还有一系列命令行工具来进行数据转换和处理。

你可能感兴趣的:(OpenCV学习笔记)