import cv2
import numpy as np
# img = np.zeros((480,640), dtype=np.uint8)
img = np.zeros((480,640,3), dtype=np.uint8)
# 提取子矩阵
roi = img[100:400,100:600]
roi[:,:] = [0,0,255] # :,: 代表指定区域的所有元素
# roi[:] = [0,255,0] 最简缩写
# roi[:,10] = [255,0,0] # [:,10] 选中的是 ROI 区域中第10列的所有像素点 ; : 表示所有行
roi[10:200,10:200] = [0,255,0]
# 创建黑底图片
while True:
# 转换颜色空间
cv2.imshow('img', roi)
key = cv2.waitKey(10)
if key & 0xFF == ord('q'):
break
cv2.destroyAllWindows()