FaceDetectPython
FaceDetect is a face detection and recognition framework built in Python on top of the work of several open source projects and models with the hope to reduce the entry barrier for developers and to encourage them to focus more on developing innovative applications that make use of face detection and recognition.
Install / Use
/learn @DoryAzar/FaceDetectPythonREADME
FaceDetect: Face detection & recognition
- By: Dory Azar

Content
- Project Status
- Project Synopsis
- Resources
- Let's get started
- Let's get through the basics
- Let's have some fun
- Known Issues
Project Status
All the features described below have been implemented for this project. The core logic that we created can be found in FaceDetect > facedetect.py
- The foundation for the framework has been completed. FaceDetect has been implemented and packaged as a class that just needs to be imported for usage.
- The framework allows reading images, videos and webcam streams
- The framework allows for customization in 2 ways:
- By providing a settings dictionary to the constructor to adjust the native features
- By extending the FaceDetect class to create more elaborate features
- Face Detection has been implemented for all 3 media. The faces can now be detected in images, videos and live webcams
- Ability to either draw rectangles around the detections or print them to the console has been implemented
- Ability to extract detected faces into separate individual images has been implemented
- Ability to detect facial features and draw them on top of either medium has been implemented
- Ability to recognize faces in a video, webcam or image based on known faces provided as image inputs
- Ability to identify recognized faces visually in a video, webcam or image
- Ability to access detection and recognition data through extensibility for use in other programs
- All the features are documented in the README
Project Synopsis
Detecting human faces and recognizing faces and facial expressions have always been an area of interest for different applications such as games, utilities and even security. With the advancement of machine learning, the techniques of detection and recognition have become more accurate and precise than ever before.
However, machine learning remains a relatively complex field that could feel intimidating or inaccessible to many of us. Luckily, in the last couple of years, several organizations and open source communities have been developing tools and libraries that help abstract the complex mathematical algorithms in order to encourage developers to easily create learning models and train them using any programming languages.
As part of this project, we will create a Face Detection framework in Python built on top of the work of several open source projects and models with the hope to reduce the entry barrier for developers and to encourage them to focus more on developing innovative applications that make use of face detection and recognition.
Artificial Intelligence (AI) and Machine Learning in particular don't have to be difficult and we hope that the FaceDetect framework gives developers the means to include face detection and recognition in a seamless way in their applications.
The framework aims to provide an easy way for developers to detect faces, facial features and recognize faces from an image, a video or a live cam stream.
Here are some of the features that we are considering. We will try to do as many as time allows:
- Detect faces in an image, video or live webcam
- Extract detected faces in separate images from the main image
- Detect and draw facial features (eyes, noses, ears etc.)
- Recognize previously saved faces in an image, video or live webcam
- Generate live data from detections that can be shared and used in other programs (extensibility)
Resources
-
Face Recognition by Adam Geitgey
The face-recognition python library was created by Adam Geitgey. It uses deep learning for face detection and recognition using the Python dlib library.
-
Open CV:
While Open CV is a great library to implement face detection and recognition, it will mainly be used in this project for capturing a stream from the webcam.
Let's get started
Environment
Python 3.8+ - Anaconda installation
One of the easiest ways to install Python is to use packaged distributions. Anaconda is one such distribution. If you are new to Python, we recommend that you install the Anaconda distribution.
If you already have Anaconda installed, all you need to do is to update it and make sure that you are using the latest version of Python. You can do this from the command line or the terminal:
conda update conda
conda update anaconda
conda update python
Recommended Editor (IDE)
You can use any development environment or editor that you are comfortable with. In this course, we will be using PyCharm. You can download the free Community Edition version.
Requirements
There are several libraries and packages needed to run this program successfully. We will provide the instructions on how to download on Mac/Linux machines:
cmake
In order to successfully install and build all the dependencies locally, CMake needs to be installed for python
// Use Homebrew to install Cmake
brew install cmake
dlib
C++ library that provides machine learning tools to be used in several other languages such as python.
// use pip to install dlib
python -m pip install dlib
face-recognition
library built on top of dlib that facilitates the usage of face detection and face recognition
// use pip to install face-recognition
pip install face-recognition
Open CV
Open source computer vision library that provides machine AI vision
//use pip to install opencv
pip install opencv-python
PIL: Python Imaging Library
PIL is a native Python library. It is used in this project for image manipulations.
<br />Numpy
Numpy is a native Python library. It is used for multi-dimensional array manipulations. It is used in this project for image array manipulations and matrices conversions
<br />Installation
You can install the FaceDetect application from github
git clone https://github.com/DoryAzar/FaceDetectPython
FaceDetect Structure
The distribution comes with several scripts that are explained herewith:
-
FaceDetect > facedetect.py:
facedetect.pyis the core logic that we created that makes all the magic happen. The FaceDetect class and all its features and functionalities are implemented in this script. The script is open source and can be modified and adjusted as needed within the boundaries of an MIT license. -
main scripts: In the root folder of the distribution, there are several scripts that start with
main.... This series of scripts are examples of how FaceDetect is used in different situations. -
resources: The
resourcesfolder contains example images to test out face detection and recognition. They are used by the main scripts. -
outputs: The
outputsfolder contains screenshots of the example programs in action used for documentation purposes
Testing the installation
The main.py script provided with the distribution provides an initial boiler plate main to test out the installation.
It can be run either in the terminal or using Anaconda PyCharm
-
Using the terminal
python main.py -
Using Anaconda PyCharm
- After installing the dependencies, set up a new Anaconda project with a Python 3.8 Virtual Environment.
- Make sure to create a fresh new virtual environment in the folder containing the FaceDetect distribution
- Run
main.py
Let's get through the basics
Understanding Face detection and recognition
Detection and Recognition are two different concepts. While both use machine learning and neural networks in particular, they achieve different things. Understanding the distinction is key to better understanding how the FaceDetect framework operates.
-
Face detection: Face detection is about identifying a human face among all other "things" perceived through either an image or a video. So for example, a picture or a video can have people, objects, scenery etc... Face detection is when the system is capable of pointing out the presence of a human face among all those other things.
-
Face recognition: Recognition is about identifying who the human face is among all other faces and things perceived. So for example, Face recognition is when the system is capable of pointing out "Flash" among all other superheroes in a picture or a video.
Understanding the framework
FaceDetect relies on an important principle: "First you detect then you do something with the detections". What we do with the detections is really what this framework is all about. On one hand, it provides cool native features such as drawing rectangles around them, labeling them, recognizing the faces etc. On the other, it provides a way to extend its capabilities by writing custom features
Getting Started with FaceDetect
- Start by creating a new python script file in the root of the distribution folder FaceDetectPython (similarly to main.py that is provided with the distribution
