Preprocessing detected faces

After a face has been detected, we might want to preprocess the extracted head region before applying classification to it. Although the face cascade is fairly accurate, for the recognition, it is important that all the faces are upright and centered on the image.

Here is what we want to accomplish:

Image credit—Lenna.png by Conor Lawless is licensed under CC BY 2.0

As you can see from the preceding screenshot, as this is not a passport photo, the model has her head slightly tilted to the side while looking over her shoulder. The facial region, as extracted by the face cascade, is shown in the middle thumbnail in the preceding screenshot.

In order to compensate for the head orientation and position in the detected box, we aim to rotate, move, and scale the face so that all data samples will be perfectly aligned. This is the job of the align_head method in the FaceDetector class, shown in the following code block:

    def align_head(self, head):
desired_eye_x = 0.25
desired_eye_y = 0.2
desired_img_width = desired_img_height = 200

In the previous code, we have hardcoded some parameters that are used to align the heads. We want all eyes to be 25 % below the top of the final image and 20 % from the left and right edges, and this function is going to return a processed image of the head that has a fixed size of 200 x 200 pixels.

The first step of the process is to detect where the eyes are in the image, after which we will use their location to construct the necessary transformation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.191.150.109