Skip to content

HamzaOuggadi/Facial-Recognition-Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Facial Recognition & Detection

Using livestream from webcam/integrated camera


Logo

This Project was made using OpenCV and Python


Explore the OpenCV docs »

View Demo (Under Construction) · Report Bug · Request Feature

Note This Project is still under construction and continuous improvement, nothing is final.

Table of Contents
  1. About The Project
  2. Built With
  3. Video Sample
  4. Installation and usage
  5. Contributing
  6. Contact
  7. Acknowledgments

About The Project

This Project was achieved using OpenCV and Python for Face Detection and Face Recognition.

OpenCV (Open Source Computer Vision Library) is an open source computer vision and machine learning software library.

(back to top)

Built With

  • Python
  • OpenCV

With OpenCV we have a choice from multiple algorithms for Face Recognition :

  • Eigenfaces.
  • Fisherfaces.
  • Local Binary Patterns Histograms.

I've used the Local Binary Patterns Histograms algorithm.

LBPH (Local Binary Pattern Histogram) is a Face-Recognition algorithm it is used to recognize the face of a person. It is known for its performance and how it is able to recognize the face of a person from both front face and side face.

It's a simple yet very efficient texture operator which labels the pixels of an image by thresholding the neighborhood of each pixel and considers the result as a binary number.

Note that face recognition is different of face detection :

  • Face Detection: it has the objective of finding the faces (location and size) in an image and probably extract them to be used by the face recognition algorithm.
  • Face Recognition: with the facial images already extracted, cropped, resized and usually converted to grayscale, the face recognition algorithm is responsible for finding characteristics which best describe the image.

So in order to get good recognition rates you'll need at least 8(+-1) images for each person and the Fisherfaces method doesn't really help here. The above experiment is a 10-fold cross validated result carried out with the facerec framework at: https://github.com/bytefish/facerec. This is not a publication, so I won't back these figures with a deep mathematical analysis. Please have a look into [168] for a detailed analysis of both methods, when it comes to small training datasets.

  • LBPH is one of the easiest face recognition algorithms.
  • It can represent local features in the images.
  • It is possible to get great results (mainly in a controlled environment).
  • It is robust against monotonic gray scale transformations.
  • It is provided by the OpenCV library (Open Source Computer Vision Library).

Video Sample

Video Demo :

IMAGE ALT TEXT HERE

(back to top)

Installation and Usage

The following packages are needed for this project to work properly :

pip install opencv-python
pip install pillow --upgrade

Imports :

import cv2
import numpy as np
import os
import pickle
from PIL import Image

Face Detection :

For Face Detection a Cascade Classifier (haarcascade_frontalface_alt2.xml) was used, it can be found in the following directory :

/cascades/haarcascade_frontalface_alt2.xml
face_cascade = cv2.CascadeClassifier('cascades/haarcascade_frontalface_alt2.xml')

The input for Face Detection/Recognition is from the default Camera in your Machine.

Here is the code responsible for it :

cap = cv2.VideoCapture(0)
faces = face_cascade.detectMultiScale(grayedFrame, scaleFactor=1.5, minNeighbors=5)

Training the Algorithm :

To train the Algorithm several photos were used from photos found on the internet of celebrities and yours truly :

├───images
│   ├───Emilia-Clarke
│   ├───Hamza-Ouggadi
│   ├───Jeff-Bezos
│   └───Peter-Dinklage

The names of the folders were used as labels for each person while training.

recognizer = cv2.face.LBPHFaceRecognizer_create()

The training creates a .yaml file that can be used on other inputs for recognition.

recognizer.train(x_train, np.array(y_labels))
recognizer.save("trainner.yaml")

As can be seen below :

recognizer.read("trainner.yaml")

(back to top)

Contributing

If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

Contact

Hamza Ouggadi - hamza.ouggadi@gmail.com

Project Link: https://github.com/HamzaOuggadi/Facial-Recognition-Detection

(back to top)

Acknowledgments

(back to top)

About

Facial Recognition & Detection using live camera feed.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published