This tool uses dlib and OpenCV to detect faces, extract them and recognizes them.
It is divided into two parts:
- Facial Detection & Extraction & Aligment
- Facial Recognition
Two scripts are availables here:
myStaticFacialDetector.py
which detects faces and computes facial landemarks on images ;myWebcamFacialAligment.py
, the main script here, which:- Launch the webcam ;
- Detect the faces ;
- Compute the facial landemarks ;
- Extract the faces ;
- Align the extracted faces and display them.
import dlib
import cv2
import math
import numpy as np
> python myWebcamFacialAlignement.py
The script myWebcamFacialRecognition.py
uses the previous face detection and recognize the faces within a dataset. You can use one or more images per faces, the algorithm will just output the name with the highest similarities.
To add a new face in the dataset, add the corresponding .jpg file in the data/images/knownFaces/ folder:
FaceDetection-Recognition
├── data
│ ├── gifs
│ │ └── *.gif
│ ├── images
│ │ ├── faces
│ │ │ └── *.jpg
│ │ └── knownFaces
│ │ └── *.jpg *Here you can add your images*
│ └── models
│ └── *.dat
├── Detection
│ └── ...
├── Recognition
│ └── ...
└── README.md
import glob
import ntpath
import dlib
import cv2
import math
import numpy as np
import face_recognition
> python myWebcamFacialRecognition.py
To see a practical example with more details explanations of the method used, please refer to my other repo DoppelGanger