Real-time face detection

In this project, I've to use OpenCV and Viola-Jones Algorithm to build a face detection system that works in real-time.

Real-time face detection

In this project, I've to use OpenCV and Viola-Jones Algorithm to build a simple face detection system that works in real-time.

Problem

I need to detect faces on images and from a webcam in real-time.

Task

Build an algorithm or machine learning model to detect faces on images.

Solution

I've used Python, OpenCV, and the Viola-Jones Algorithm to build a solution to detect faces fast.

Results

The solution has good accuracy and can detect faces really fast.


How to use it

To detect the face the software uses the Haar-like features with the help of the haarcascade_eye.xml and haarcascade_frontalface_default.xml files.

Prerequisites

To run this code, download Python 3 from Python.org.

After installing Python, add the required package using pip installer:

pip install -r requirements.txt

Then, clone the GitHub repository:

git clone https://github.com/cpatrickalves/cv-realtime-face-detection

Usage

To run the detection in real-time using the webcam, run:

python face_recognition.py

To perform the face detection on an image, just add the file name as an argument:

python face_recognition.py -f image.jpg

The script will create an output with a similar name. It with add the _output in the file name (ex: image_output.jpg)

Add the -s flag to perform smile detection.

Example


Web application

You can also run this script as an Streamlit application:

streamlit run app.py

It will automatically open the browser and show the app.

webapp.png

Built With

  • Python - Programming Language.
  • OpenCV - Open Computer Vision Library.
  • Streamlit - Open-source app framework for Machine Learning and Data Science teams.

Source code

The source code is available at Github.

github