Opencv中对彩色图的操作同样可以应用于灰度图和二值图,彩色图与灰度图直接的区别在于颜色类型空间类型的不同,这里以彩为操作示例。RGB、BGR、LAB、HSV是常见的3通道(CV_8UC3、CV_32FC3)彩色图类型,灰度图通常是一个通道的图像,二值图的数据类型与灰度图是一样的(CV_8UC1)。
一、读取|保存图像
imread函数用于读取图像,imread( const String& filename, int flags = IMREAD_COLOR ),flags的默认值为IMREAD_COLOR,也就是说默认读取为三通道BGR图像。完整的图像加载模式如下所示,0表示读取为灰度图。
IMREAD_UNCHANGED = -1, //!< If set, return the loaded image as is (with alpha channel, otherwise it gets cropped). Ignore EXIF orientation.
IMREAD_GRAYSCALE = 0, //!< If set, always convert image to the single channel grayscale image (codec internal conversion).
IMREAD_COLOR = 1, //!< If set, always convert image to the 3 channel BGR color image.
IMREAD_ANYDEPTH = 2, //!< If set, return 16-bit/32-bit image when the input has the corresponding depth, otherwise convert it to 8-bit.
IMREAD_ANYCOLOR = 4, //!< If set, the image is read in any possible color format.
IMREAD_LOAD_GDAL = 8, //!< If set, use the gdal driver for loading the image.
IMREAD_REDUCED_GRAYSCALE_2 = 16, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/2.
IMREAD_REDUCED_COLOR_2 = 17, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/2.
IMREAD_REDUCED_GRAYSCALE_4 = 32, //!< If set, always convert image to the single channel grayscale image and the image size reduced 1/4.
IMREAD_REDUCED_COLOR_4 = 33, //!< If set, always convert image to the 3 channel BGR color image and the image size reduced 1/4.
IMREAD_REDUCED_GRAYSCALE_8 = 64, //!< If set, always convert image to the single channel grayscale image and the image size re

最低0.47元/天 解锁文章
2万+

被折叠的 条评论
为什么被折叠?



