Advanced drawing

In this section, we are going to see how to combine some of the aforementioned functions to draw basic shapes in OpenCV (for example, lines, circles, rectangles, and text, among others) to render a more advanced drawing. To put all these pieces together, we have built an analog clock to show you the current time (hour, minutes, and seconds). For this, two scripts are coded:

  • analog_clock_values.py
  • analog_clock_opencv.py

The analog_clock_opencv.py script draws an analog clock, using cv.line(), cv.circle(), cv.rectangle(), and cv2.putText(). In this script, we first draw the static drawing. In this sense, you can see that there are two arrays containing fixed coordinates:

hours_orig = np.array(    [(620, 320), (580, 470), (

Get Mastering OpenCV 4 with Python 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.