The OpenCV 4 source code, or your installation of a prepackaged build of OpenCV 4, should contain a subfolder called data/haarcascades. If you are unable to locate this, refer back to Chapter 1, Setting Up OpenCV, for instructions on obtaining the OpenCV 4 source code.
The data/haarcascades folder contains XML files that can be loaded by an OpenCV class called cv2.CascadeClassifier. An instance of this class interprets a given XML file as a Haar cascade, which provides a detection model for a type of object such as a face. cv2.CascadeClassifier can detect this type of object in any image. As usual, we could obtain a still image from a file, or we could obtain a series of frames from a video file or a video camera.
Once you find data/haarcascades, create a directory elsewhere for your project; in this folder, create a subfolder called cascades, and copy...