@briefLoadsanimagefromafile。
@anchorimread
thefunctionimreadloadsanimagefromthespecifiedfileandreturnsit.iftheimagecannotbe
读取(becauseofmissingfile,improperpermissions,unsupportedorinvalidformat ),thefunction
returnsanemptymatrix (mat :3360数据==null )。
函数imread从指定的文件加载并返回图像。 如果由于文件丢失、权限不正确、不支持或格式无效而无法读取图像,函数将返回空矩阵。 (Mat:data==NULL )。
当前支持的格式:
当前,thefollowingfileformatsaresupported :
-Windowsbitmaps-*.bmp, *.DIB (全部支持) ) ) ) ) ) ) )。
-JPEGfiles-*.jpeg、*.jpg、*.JPE(seethe*note*section ) ) ) ) ) 0
- JPEG 2000文件- *.jp2 (see the * note * section ) ) ) ) ) )。
-可移植网络图形- *.png (see the * note * section ) () ) ) ) 0
- webp-*.webp (see the * note * section ) ) ) ) ) ) ) )。
-可移植图像格式*.pgm、*.pgm、*.ppm*.pxm、*.pgm (允许支持) ) ) ) )
- PFM files-*.PFM (see the * note * section () ) ) ) ) ) ) ) ) )。
-Sunrasters-*.sr, *.ras (所有支持) ) ) )。
-TIFFfiles-*.tiff,*.TIF(seethe*note*section ) ) ) ) ) ) )。
- openexrimagefiles-*.exr (see the * note * section ) ) ) ) ) ) ) ) )。
-RadianceHDR-*.hdr, *.pic (所有支持) ) ) ) )。
- rasterandvectorgeospatialdatasupportedbygdal (see the * note * section ) ) ) ) ) 0
@note注意事项
- thefunctiondeterminesthetypeofanimagebythecontent,notbythefileextension http://www.Sina.com /
-Inthecaseofcolorimages,thedecodedimageswillhavethechannelsstoredin * * bgr * * order.http://www.Sina.com /
-WhenusingIMREAD_GRAYSCALE,thecodec ' sinternalgrayscaleconversionwillbeused,if available.resultsmaydiffertotheoutputpute 结果可能与cvtColor ()的输出不同
-OnMicrosoftWindowsOSandMacOSX,thecodecsshippedwithanopencvimage (libjpeg,
libpng,libtiff,andlibjasper (areusedbydefault.so,OpenCVcanalwaysreadJPEGs,PNGs,
andTIFFs.OnMacOSX,thereisalsoanoptiontousenativemacosximagereaders.but beware
thatcurrentlythesenativeimageloadersgiveimageswithdifferentpixelvaluesbecauseof
thecolormanagementembeddedintomacosx。
-OnLinux*,BSDflavorsand
other Unix-like open-source operating systems, OpenCV looks forcodecs 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.
- In the case you set *WITH_GDAL* flag to true in CMake and @ref IMREAD_LOAD_GDAL to load the image,
then the [GDAL](http://www.gdal.org) driver will be used in order to decode the image, supporting
the following formats: [Raster](http://www.gdal.org/formats_list.html),
[Vector](http://www.gdal.org/ogr_formats.html).
- If EXIF information is embedded in the image file, the EXIF orientation will be taken into account
and thus the image will be rotated accordingly except if the flags @ref IMREAD_IGNORE_ORIENTATION
or @ref IMREAD_UNCHANGED are passed.
- Use the IMREAD_UNCHANGED flag to keep the floating point values from PFM image.
- By default number of pixels must be less than 2^30. Limit can be set using system
variable OPENCV_IO_MAX_IMAGE_PIXELS
@param filename Name of file to be loaded.
@param flags Flag that can take values of cv::ImreadModes
*/
CV_EXPORTS_W Mat imread( const String& filename, int flags = IMREAD_COLOR );
函数原型
Mat clone() const;void copyTo( OutputArray m ) const;void copyTo( OutputArray m, InputArray mask) const;copyTo()有重载,
inline Mat Mat::clone() const{ Mat m; copyTo(m); return m;}opencv矩阵赋值函数copyTo、clone、重载元算赋‘=’之间实现的功能相似均是给不同的矩阵赋值功能。
copyTo和clone函数基本相同,被赋值的矩阵和赋值矩阵之间空间独立,不共享同一空间(深拷贝)。
但是重载元算赋‘=’,被赋值的矩阵和赋值矩阵之间空间共享,改变任一个矩阵的值,会同时影响到另一个矩阵(浅拷贝)。当矩阵作为函数的返回值时其功能和重载元算赋‘=’相同,赋值运算赋会给矩阵空间增加一次计数,所以函数变量返回后函数内部申请的变量空间并不会被撤销,在主函数中仍可以正常使用传递后的参数。