【OpenCV笔记 01】OpenCV基本函数介绍

本文主要介绍OpenCV基本函数,包括imread(), imshow(), namedWindow(), imwrite(),函数功能分别对应图像载入,图像显示,创建窗口,输出图像到文件

1.函数imread(),用于图像的载入。

1.1函数原型
 Mat cv::imread
( const String &  filename, 
    int  flags = IMREAD_COLOR       
  )    

备注:第一个参数为文档名第二个参数flag 为int类型的载入标识,指定加载图像的颜色类型             

1.2参数列表(用于参数说明) Parameters
filename Name of file to be loaded. 
flags Flags specifying the color type of a loaded image:
  • CV_LOAD_IMAGE_ANYDEPTH - If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
  • CV_LOAD_IMAGE_COLOR - If set, always convert image to the color one
  • CV_LOAD_IMAGE_GRAYSCALE - If set, always convert image to the grayscale one
  • **>0** Return a 3-channel color image.

备注:如果flag>0,返回一个三通道的彩色图像,flag=0返回一个灰度图像,flag<0,返回包含Alpha通道的加载图像
用法举例:
Mat image1 = imread("try,jpg", 2 | 4);//载入无损的原图像
Mat image2 = imread("try,jpg", 0);//载入灰度图像
Mat image3 = imread("try,jpg", 199);//载入三通道彩色图像


Note
In the current implementation the alpha channel, if any, is stripped from the output image. Use negative value if you need the alpha channel.
  • **=0** Return a grayscale image.
  • **<0** Return the loaded image as is (with alpha channel).

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:

  • 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)
    备注:imread函数支持以上格式的图像载入,有比较常用bmp,jpg,png,tiff等。
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.
  • 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.
备注:在彩色图像的条件下,解码图像将会有RGB三色通道的存储信息


具体可以参考官方给出的OpenCV3.0.0参考手册,网址http://docs.opencv.org/3.0-rc1/

访问路径:

【Main modules】》》【imgcodecs. Image file reading and writing】》》【Function】》》【imread()】


你可能感兴趣的:(C++,OpenCV,OpenCV,3.0,学习笔记,opencv,函数,计算机视觉)