/face-access

Basic example of access control with face recognition

Primary LanguagePythonMIT LicenseMIT

Face Access

Access control (Arduino controled) with face recognition (On PC)

  • Multi Platform
  • MIT License
  • LGPDP Brasil Safe (Lei Geral de Proteção de Dados Pessoais)

TODO List

  • Basic command line interface
  • Face recogniton from Webcam
  • Just use the photo once for register, after that discard. Save only a id on the local file database (LGPDP Brasil Safe).
  • OneTimePassword with Google Authenticator
  • Text to Speech for welcome audio message
  • Arduino commands to open the door
  • Qr-Code to easy registration and temporary access
  • Audio code (CHIRP) to easy registration and temporary access
  • Use requirements.txt to Easy Install
  • Easy Install for Windows

Improvements

*Easy QR-Code face register demonstration

Technologies and Libraries

Requirements

  • Python 3.6+
  • Cmake(Linux and Windows) or XCode (MacOS)
  • MacOS or Linux (Tested with Ubuntu 18.04).
    • Windows not officially supported by DLib and Face Recoginition library, but might work (slowly)
  • I strongly recommend that you use a package manager like Homebrew (MacOS), apt-get (Ubuntu) and Chocolatey (Windows)

Easy install

You can copy and paste these commands to install all dependencies or going step-by-step in this tutorial to understand each part or if something not working.

*if pip3 command not working use pip instead

**if something not work, try to reboot the terminal. :)

MacOS

xcode-select --install
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
brew install git cmake python3 zbar portaudio libsndfile
git clone https://github.com/alexandremendoncaalvaro/face-access.git
cd face-access
pip3 install virtualenv
virtualenv cv
source cv/bin/activate
pip3 install -r requirements.txt

Ubuntu

sudo apt update && sudo apt upgrade
sudo apt-get install git build-essential cmake python3 python3-pip libzbar-dev libzbar0 python3-dev python3-setuptools portaudio19-dev libffi-dev libsndfile1
git clone https://github.com/alexandremendoncaalvaro/face-access.git
cd face-access
pip3 install virtualenv
virtualenv cv && source cv/bin/activate
pip3 install -r requirements.txt

Windows

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
choco install git cmake python3 zbar -Y
git clone https://github.com/alexandremendoncaalvaro/face-access.git &&
cd face-access
pip3 install virtualenv
virtualenv cv &&
cv\Scripts\activate
pip3 install sounddevice_file_name.whl
  • Replace the file name with the same of the downloaded file
pip3 install -r requirements.txt

Install (step-by-step)

Package Manager installation

Homebrew (Mac)

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Update apt (Ubuntu)

sudo apt update
sudo apt upgrade

Chocolatey (Windows)

@"%SystemRoot%\System32\WindowsPowerShell\v1.0\powershell.exe" -NoProfile -InputFormat None -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"

Cmake / XCode

MacOS

  • Install XCode from App Store

then:

xcode-select --install
brew install cmake

Ubuntu

sudo apt install build-essential cmake

Windows

choco install cmake -Y

Or manually install from: https://cmake.org/download/

*Add Cmake installation directory path to System path.

Python 3.6+ with PIP

*I strongly recomend you to know about (and maybe use) Virtual Enviroments

*if pip3 command not working use pip instead

MacOS

brew install python3

*more details..

Ubuntu

sudo apt install python3 python3-pip

Windows

choco install python3 -Y

Virtual Enviroments

*It's optional, but I strongly recomend you to know about (and use) Virtual Enviroments

The virtualenv lib is a tool to create isolated Python environments. virtualenv creates a folder which contains all the necessary executables to use the packages that a Python project would need.

pip command

pip3 install virtualenv

You can create a virtualenv using the following command (*choose a name, I used cv):

virtualenv cv

Activate it:

MacOS & Ubuntu

source cv/bin/activate

Windows

cv\Scripts\activate

Now ALL pip libraries will be installed isolated inside the environment. It'll look like this:

(cv)$ pip3 install ...

If you want to deactivate:

(cv)$ deactivate

Command:

deactivate

OpenCV

pip command

pip3 install opencv-contrib-python

*Complete Tutorial from pyimagesearch

DLib + Face Recognition (ageitgey)

pip command

pip3 install dlib

*How to install dlib from source on macOS or Ubuntu

*How to install dlib from source on Windows: While Windows isn't officially supported, helpful users have posted instructions on how to install this library:

pip command

pip3 install face_recognition

Arduino control with pyFirmata2

You will need an Arduino Board like Uno, Mega, Micro, Nano with a relay module and a solenoid Door lock to control the access.

Install Arduino IDE and use the Example > Firmata > StandardFirmata on the board.

The board need to stay connected over USB. All the Arduino (GPIO) control will be done by the python code.

This algorithm automatically detects the serial port of the Arduino. If this fails you can also specify the serial port manually, for example: board = Arduino('COM4')

Under Linux this is usually /dev/ttyUSB0. Under Windows this is a COM port, for example COM4. On a MAC it’s /dev/ttys000, /dev/cu.usbmodem14101 or check for the latest addition: ls -l -t /dev/*.

pip command

pip3 install pyfirmata2

Google Text 2 Speech

pip command

pip3 install gTTS

Google One Time Password (Google Authenticator)

pip command

pip3 install pyotp

QR-Code

MacOS

brew install zbar

Ubuntu

sudo apt-get install libzbar-dev libzbar0

Windows

choco install zbar -Y

pip command

pip3 install pyzbar pyqrcode pypng

Welcome Audio (Pygame Mixer)

pip command

pip3 install pygame

Audio Code - CHIRP

You will need generate keys to use this lib. [Official instructions] (https://developers.chirp.io/docs/getting-started/python)

MacOS

brew install portaudio libsndfile

Ubuntu

sudo apt-get install python3-dev python3-setuptools portaudio19-dev libffi-dev libsndfile1

Windows

pip3 install sounddevice_file_name.whl

*Replace the file name with the same of the downloaded file

pip command

pip3 install chirpsdk

After installation

To start, with terminal go to folder path and execute:

python main.py

Config file:

You can change a lot of configurations using config.py file

CLI commands:

If everything is right, a new window with the webcam streaming and face recognition will start. In the terminal you should see somethong like:

CMD:

*Don't use spaces BETWEEN parameters, they are separated by comma (,). But you can use spaces IN parameter, like: Firstname Middlename Lastname..

Where you can do some actions like:

Create a QR-Code to show to the camera and easelly register a new face:

qr,Joseph Smith

Add a new face id from a image file in the folder images:

add,Joseph Smith,images/joseph.jpg

Add a new face id from the current webcam capture:

add,Joseph Smith

List the current face ids:

print

Remove a face id:

del,Joseph Smith

Exit:

q

or

quit

Are you a native english speaker?

No, I am not. If you find typos, grammar errors or whatever please feel free to PR or tell me.