Face Detection with Haar Cascade — Part II | by Girija Shankar Behera | Dec, 2020
Load the Face Model
Okay, we imported the image files. Now we bring in the Haar models for the detection part. The Haar Cascade will be read through the OpenCV library from the GitHub repository. Looking at the repository once, it has a number of models available. It includes models for face detector, upper and lower body detector, eye detector, license place detectors etc. We, in this article, will use the models for face and eye both.
The models are simple XML files with all the data stored in them. OpenCV provides a CascadeClassifier method which imports the model from its GitHub repository. Then we write a method which will accept an image, and uses the model to detect the faces in the image. The method first converts the image to GrayScale format, as ML models generally work on GrayScale data as they consist of a single layer.
Then we use the GrayScale data with the model imported. It produces a list of coordinates for all the faces found in the photo. We iterate on each of the entries in the coordinate list, it contains the x and the y coordinates and the width and the height. Then we create a rectangle with these values and fill in with a random color. We then display the image with the face coordinates in the colored rectangles.
Let’s not see the images now, and wait for the eye model to get done with its detection also.
Read More …