文档中是这么写的:

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 oneCV_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).
大致翻译一下:

Flags指定了所读取图片的颜色类型

CV_LOAD_IMAGE_ANYDEPTH返回图像的深度不变。

CV_LOAD_IMAGE_COLOR总是返回一个彩色图。

CV_LOAD_IMAGE_GRAYSCALE总是返回一个灰度图。

0返回3通道彩色图

注意:alpha 通道将被忽略,如果需要alpha 通道,请使用负值

=0返回灰度图

<0返回原图(带alpha 通道)

我觉得这里最大的问题就是一会说深度,一会说通道数,两个问题都没有说明白。

实测,当读取一副黑白图时,如果使用Flags=2(CV_LOAD_IMAGE_ANYDEPTH),此时Flags>0,得到的仍是黑白图而不是彩色图。其它的值,如1,3,4等均是彩色。

所以我觉得第一句话应该改为  CV_LOAD_IMAGE_ANYDEPTH返回图像原有的深度,但是通道数变为1,这是Flags>0中的特例

在源码中可以看到

自己测了一下,然后总结如下:

flag=-1时,8位深度,原通道

flag=0,8位深度,1通道

flag=1,   8位深度  ,3通道

flag=2,原深度,1通道

flag=3,  原深度,3通道

flag=4,8位深度 ,3通道


作者:阿翔ax
来源:CSDN
原文:https://blog.csdn.net/z914022466/article/details/52709981?utm_source=copy
版权声明:本文为博主原创文章,转载请附上博文链接!

posted on 2018-10-10 19:10  泰坦妮克号  阅读(5195)  评论(0编辑  收藏  举报