这里主要记录一下imread的第二个参数flag,再实际的使用中,可以不使用这个参数,则其取的是默认值。
一般情况下,flag有3种取值:
-1:原图
0:灰度图
1:彩色图
若不使用flag,则默认值为1,即彩色图像。
文档中是这么写的:
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.
- 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).