OpenCV based face recognition system that can detect and recognize multiple faces in an image. This project is based on this, which had only single face detection. I have implemented a multiple face recognition system.
There are 2 parts in a face recognition system.
- Face Detection - To detect faces in images.
- Face Recognition - To recognize face of persons in the images.
Face detection is acheived in this project using Haar Cascade classifier. It could be used for object detection. Here we are using it for detecting faces. The official documentation of the project is available here.
We are using LBPH (Local Binary Patterns Histograms ) classifier to recognize the faces from the images. It compares neighboring pixels of a pixel and creates a histogram out of it for comparing faces. We could also use algorithms such as, EigenFaces Face Recognizer and FisherFaces Face Recognizer. The official Documentaion is available here.
These 3 algorithms could be added to the project by changing a single line.
EigenFaces Face Recognizer Recognizer - cv2.face.createEigenFaceRecognizer()
FisherFaces Face Recognizer Recognizer - cv2.face.createFisherFaceRecognizer()
Local Binary Patterns Histograms (LBPH) Face Recognizer - cv2.face.createLBPHFaceRecognizer()
To run the program, in terminal type python facemaster.py
The photos of each individual should be stored in a folder s[i] (s1, s2 etc) inside the training-data folder. Test images are stored in test-data folder.
The application is built over 3 files.
- facemaster.py - Create the recognizer, train the images using
training_data()
and makes predictions from test data usingpredict()
function. - training_data.py - To parse through each images in the training set and call
face_detect()
on each image. - face_detect.py - To detect the face, here we are initializing Haar Cascade classifier to detect multiple faces from the image, draw bounding boxes over face and returns the face bonding box coordinates.