1.安装opencv
pip install opencv-python
2.简单举例
(1)具体代码如下
import cv2
import numpy as np
# (400, 300, 3):高度,宽度,维数
img_array = np.zeros((400, 300, 3))
# 蓝绿红
img_array[100][200] = (255, 0, 0)
cv2.imshow('black', img_array)
cv2.waitKey(0)
cv2.destroyAllWindows()
效果如下:
(2) 具体代码如下
import cv2
import numpy as np
black_arraty= np.zeros((100, 150, 3), dtype=np.uint8)
for x in range(100):
for y in range(150):
if x <= 100//3:
black_arraty[x][y] = (0, 0, 255)
elif x <= 2*100//3:
black_arraty[x][y] = (0, 255, 0)
else:
black_arraty[x][y] &