如下實驗基於python==3.六、opencv-python==4.1.0.2五、imutils==0.5.2html
該方法第一個參數爲文件名filename(文件路徑+文件名)python
第二個爲讀取方式flags,可選參數git
IMREAD_ANYCOLOR = 4 IMREAD_ANYDEPTH = 2 IMREAD_COLOR = 1 IMREAD_GRAYSCALE = 0 IMREAD_IGNORE_ORIENTATION = 128 IMREAD_LOAD_GDAL = 8 IMREAD_REDUCED_COLOR_2 = 17 IMREAD_REDUCED_COLOR_4 = 33 IMREAD_REDUCED_COLOR_8 = 65 IMREAD_REDUCED_GRAYSCALE_2 = 16 IMREAD_REDUCED_GRAYSCALE_4 = 32 IMREAD_REDUCED_GRAYSCALE_8 = 64 IMREAD_UNCHANGED = -1
前4中讀取方式的shape和顯示效果以下github
可見IMREAD_GRAYSCALE
和IMREAD_ANYDEPTH
都只讀取了一層灰度圖像測試
而IMREAD_COLOR
和IMREAD_ANYCOLOR
讀取了3層彩色圖像3d
由於這裏只測試了jpeg圖片,可能在讀取其餘圖片的狀況下會有不一樣結果,你們能夠本身試一下code
cv2.IMREAD_GRAYSCALE (2048, 1536) cv2.IMREAD_COLOR (2048, 1536, 3) cv2.IMREAD_ANYDEPTH (2048, 1536) cv2.IMREAD_ANYCOLOR (2048, 1536, 3)
下面是IMREAD_IGNORE_ORIENTATION
、IMREAD_LOAD_GDAL
、IMREAD_UNCHANGED
htm
cv2.IMREAD_IGNORE_ORIENTATION (2048, 1536) cv2.IMREAD_LOAD_GDAL (2048, 1536, 3) cv2.IMREAD_UNCHANGED (2048, 1536, 3)
下面是IMREAD_REDUCED_COLOR_2
、IMREAD_REDUCED_COLOR_4
、IMREAD_REDUCED_COLOR_8
blog
像素分別減小爲原來的1/二、1/四、1/8,但依然是彩色像圖片
cv2.IMREAD_REDUCED_COLOR_2 (1024, 768, 3) cv2.IMREAD_REDUCED_COLOR_4 (512, 384, 3) cv2.IMREAD_REDUCED_COLOR_8 (256, 192, 3)
下面是IMREAD_REDUCED_GRAYSCALE_2
、IMREAD_REDUCED_GRAYSCALE_4
、IMREAD_REDUCED_GRAYSCALE_8
像素分別減小爲原來的1/二、1/四、1/8,而且都是灰度圖像
cv2.IMREAD_REDUCED_GRAYSCALE_2 (1024, 768) cv2.IMREAD_REDUCED_GRAYSCALE_4 (512, 384) cv2.IMREAD_REDUCED_GRAYSCALE_8 (256, 192)
注:爲了方便比較,以上全部圖片在顯示的時候又統一縮放爲(512, 384)大小的圖片並排顯示
示例代碼已經上傳到github