天天看點

OpenCV python 彩色圖檔的三通道OpenCV python 彩色圖檔的三通道

OpenCV python 彩色圖檔的三通道

#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
目的:了解彩色圖檔的三通道
Created on Sat Nov 16 15:24:12 2019
@author: huzhenxing
"""
import cv2
import numpy as np

#建立 長度:600, 寬度:600 全部為0 的三維數組
img = np.zeros((600,600,3), dtype = np.uint8)
#顯示圖檔 600×600 全黑的圖檔
cv2.imshow("img_before", img)

#x方向 0到200像素列  B 藍色通道 全部置為 255
img[:, 0:200, 0] = 255
#x方向 200到400像素列  G 綠色通道 全部置為 255
img[:, 200:400, 1] = 255
#x方向 400到600像素列  R 綠色通道 全部置為 255
img[:, 400:600, 2] = 255

#列印圖檔 數組資料
print("Image = \n", img)

#顯示圖檔 三色圖檔
cv2.imshow("img_after", img)

#等待按鍵輸入 關閉視窗
cv2.waitKey (0)
cv2.destroyAllWindows()
           

結果資料

OpenCV python 彩色圖檔的三通道OpenCV python 彩色圖檔的三通道

結果圖檔

OpenCV python 彩色圖檔的三通道OpenCV python 彩色圖檔的三通道