May 2020
Intermediate to advanced
262 pages
6h 48m
English
The magic in our program is performed by the OpenCV library. We start out our code by importing it via cv2. We also import the LED class from gpiozero to control the LED that we will use for the alarm:
import cv2from gpiozero import LED
We define our image file as face.png. As there is no directory reference, be sure to have the picture located in the same directory you are running the code from.
To perform image recognition, OpenCV requires a cascade file. This is basically an XML file used to describe what a particular object looks like to the computer. In this case, it is a face in the frontal position, hence the name of the file is haarcascade_frontalface_default.xml.
We then create an alarm object by assigning it ...