Perform face recognition in video stream for registered members. This repo is based on https://www.pyimagesearch.com/2018/09/24/opencv-face-recognition/
The face recognition pipeline can be summarized as follow.
-
When an video frame is fed into the system, it first performs face detection using a pre-trained Convolution Neural Network (CNN) model (ResNet + SSD) and returns a set of Region Of Interest (ROI).
-
Then the cropped face images are passed to another pre-trained CNN model to perform face encoding (FaceNet architecture trained by OpenFace) and returns a list of 128-dimension vectors for each face.
-
Finally, face recognition is performed on the 128-dimension vectors using various methods. In this repo, we use machine learning methods including Support Vector Machine (SVM), k-Nearest Neighbours (k-NN), and Random Forest. Moreover, we also use non-machine learning methods -- Pearson correlation, Cosine similarity, L2 distance, and L1 distance.
The python scripts are written for Python 3 only and requires the following modules
- numpy
- sklearn
- opencv-python
- imutils
- tkinter
Install the first 4 modules using pip
$ pip install numpy
$ pip install sklearn
$ pip install opencv-python
$ pip install imutils
Installation of tkinter is a bit tricky since it is not included in pip
. But if you are using Anaconda Python distribution, you should have it installed already. Otherwise check out these posts.
https://stackoverflow.com/questions/4783810/install-tkinter-for-python
$ git clone https://github.com/newTypeGeek/face-recognition
$ python3 main.py
Then you will see a GUI as shown below with Total number of member = 0.
-
Registration button registers a member given the valid First Name and Last Name input. Next, user is asked to take up to 10 photos to complete the registration. The photos would be stored in
dataset/<your_name>
. Then, theTotal number of member
in GUI should be incremented by one. -
Add photos button takes additional for an existing member given the First Name and Last Name input.
-
Face Recognition (method) button starts performing face recognition from a video stream using the method.
-
Information button shows the reference of this program.
-
Restart button clears and re-generates all the
embeddings.pickle
andface_recognition_model
files, based on the current images in thedataset
directory. This button is useful if user adds or delete photos without interacting with the GUI. This procedure also occurs when the program starts (i.e.$ python3 main.py
) -
Quit button closes the program immediately.
-
main.py
The main program to be executed by Python Interpreter. It consists ofTkinter
GUI design. -
btn_funcs
A package consists of button functions of GUI -
image_embedding
A package consists of core functions:- Starting (re-starting) the
main.py
program - Register new members
- Add new photos
- Starting (re-starting) the
-
webcam
A package using webcam to perform photo taking and face recognition -
train_clf
A package to train machine learning models (classifiers) -
load_data
A package to load 128-d vectors, trained machine learning models, and pre-trained CNN models -
dataset
A directory to store photos for each identity -
face_detection_model
A directory to store a pre-trained face detection model (ResNet) -
embeddings
A directory to store a pre-trained face embedding model (FaceNet), and 128-d vectors -
classifier_model
A directory to store trained classifiers (SVM, KNN, Random Forest)
Considering to re-organise the package and write some of the codes in OO