加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

opencv中imread第二个参数的意义

发布时间:2020-12-14 04:19:31 所属栏目:大数据 来源:网络整理
导读:文档中是这么写的: 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 c

文档中是这么写的:

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 版权声明:本文为博主原创文章,转载请附上博文链接!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读