Team: ESD (Face Detection/Recognition)
Author: Robert Burke (post #5)
Action item review:
My action item for last week was to implement an extended version of the basic Face Recognition, which will then be combined with Philip’s Face Detection code to enable an image of a detected face to be captured and the identity of the face then predicted by the face recognition.
Using our combined learning from the Face Detection code and Face Recognition code myself and Philip had developed, we began combining both detection and recognition functionality to allow a face detected in the RPI camera to be passed to the face recogniser for a prediction on the identity.
For this an example taken from the internet of a more basic face recognition system was examined which uses a different database and face recognition algorithm. This allowed for both methods to be compared and contrasted while implementing a working proof of concept.
The example code uses the Yale face database which consists of 11 images of 15 distinct subjects with varying lighting conditions and facial expressions. The Linear Binary Patterns Histogram algorithm is used to recognise faces.
Figure 1: Example images from Yale face database
Instead of having negative and positive databases, a single database of all faces is used and the test image compared against all faces to predict the identity. This method suited our application more and also was observed to be more reliable and efficient. It was observed through the implementation of this code that the images being passed from the RPI camera during a continuous raw capture were of too low a quality for the Face recogniser to correctly identify the subject. Therefore for the demo video below higher quality still images are passed to the face recogniser as the camera is capturing frames to show how the system will operate.
Full code (face detection and recognition combined) available at,
The code for face recognition consists of 3 main parts, importing necessary libraries and initializing variables, the face prediction section and the face training function. The code is a composite of example code and various other scripts wrote and combined to implement the functionality within Philips face detection code which is omitted here.
Figure 2 below shows the necessary code to import the various libraries and initialize variables such as the haar face classifier function location and LBPH face recogniser function.
Figure 2: Driver imports and initialising variables
Figure 3 below shows the necessary code to predict the identity of a face by comparing it to faces in the database. The section of code consists of an if statement to check if a face has been detected in Philip’s code, a for loop to search through the folder where detected faces are stored, a for loop to predict the identity of the detected face and a series of nested if statements to determine the name of the subject for a given label.
Figure 3: Code to return prediction in face detection function
Figure 4 shows the function to extract faces and labels from the database to train the face recognizer. Because the database images have a .gif extension and the fact that OpenCv no longer support .gif files the image open was replaced by a more complicated method which converts the file into a more useful format. The for loop within the function cycles through each image with each iteration and converts the images in this manner, while also extracting the label from the image name. Also each detected face in each image in the database the face is extracted and saved in the training file.
Figure 4: Function to extract faces and labels from images in database
Raspberry Pi 2 and OpenCV 3 Tutorial Part 1
Face Recognition using Python and OpenCV
Training haar for better face
pyhton face recognition example c++
Face Recognition Methods & Applications
Open cv, face recognition documentation