You will need to perform the following steps for this recipe:
- As done previously, open an image and get its width and height. Also, make a copy of the original image and define a simple function that returns a random point with coordinates inside our image:
import cv2, numpy as np, randomimage = cv2.imread('../data/Lena.png')w, h = image.shape[1], image.shape[0]image_to_show = np.copy(image)def rand_pt(): return (random.randrange(w), random.randrange(h))
- Now when the user presses P, L, R, E, or T draw points, lines, rectangles, ellipses, or text, respectively. Also, we will clear an image when the user hits C and closes the application when the Esc key is pushed:
finish = Falsewhile not finish: cv2.imshow("result", image_to_show) ...