To get the result, it's necessary to go through a few steps:
- Import all necessary modules:
import cv2, numpy as np
- Create a matrix of a certain shape and fill it with 255 as a value, which should display the following:
image = np.full((480, 640, 3), 255, np.uint8)cv2.imshow('white', image)cv2.waitKey()cv2.destroyAllWindows()
- Create a matrix and set individual values for the colors of each pixel to color our matrix red:
image = np.full((480, 640, 3), (0, 0, 255), np.uint8)cv2.imshow('red', image)cv2.waitKey()cv2.destroyAllWindows()
- Fill our matrix with zeros to make it black:
image.fill(0)cv2.imshow('black', image)cv2.waitKey()cv2.destroyAllWindows()
- Next, set some individual pixels' values to white:
image[240, 160] ...