文檔中是這么寫的:
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
版權聲明:本文為博主原創文章,轉載請附上博文鏈接!