How to do it...

To get the result, it's necessary to go through a few steps:

  1. Import all necessary modules:
import cv2, numpy as np
  1. 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()
  1. 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()
  1. Fill our matrix with zeros to make it black:
image.fill(0)cv2.imshow('black', image)cv2.waitKey()cv2.destroyAllWindows()
  1. Next, set some individual pixels' values to white:
image[240, 160] ...

Get OpenCV 3 Computer Vision with Python Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.