python openCV 视觉 --numpy 检索和赋值

5 阅读1分钟
from itertools import count

import cv2
import numpy as np

# img = np.zeros((480,640), dtype=np.uint8)
img = np.zeros((480,640,3), dtype=np.uint8)

# 读取矩阵中某个元素中的值
print(img[100,100])
# 创建滑动条RGB
count = 0
# 向矩阵中某个元素中赋值
while count < 200:
    # img[count,100] = 255
    # img[count,100,1] = 255 # BGR
    img[count, 100] = [255,255,255]
    count += 1
# 创建黑底图片
while True:

    # 转换颜色空间

    cv2.imshow('img', img)


    key = cv2.waitKey(10)
    if key & 0xFF == ord('q'):
        break
cv2.destroyAllWindows()