Getting Haar cascade data
Your installation of OpenCV 5 should contain a subfolder called data
. The path to this folder is stored in an OpenCV variable called cv2.data.haarcascades
.
The data
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.
From the data
folder, we will use the following cascade files:
haarcascade_frontalface_default.xml
haarcascade_eye.xml
As their names suggest, these cascades are for detecting faces and eyes. They require a frontal, upright view of the subject. We will use them later when building a face detector.
If you are curious about how these cascade files are generated, you can find...