Let's learn how to draw different figure shapes, such as a line, square, or triangle, on an image using OpenCV. When we draw any shape on an image, we need to take care of the coordinates, color, and thickness of the shape. Let's first create a blank image with a white or black background:
# Import cv2 latest version of OpenCV library import cv2
# Import numeric python (NumPy) library import numpy as np
# Import matplotlib for showing the image import matplotlib.pyplot as plt
# Magic function to render the figure in a notebook %matplotlib inline
# Let's create a black image image_shape=(600,600,3) black_image = np.zeros(shape=image_shape,dtype=np.int16)
# Show the image plt.imshow(black_image)
This results in the following output:
In the preceding example, we created a blank image with a black background using the zeros() function of the NumPy module. The zeros() function creates an array of the given size and fills the matrix with zeros.
Let's create...