mlabarrere / webcam-recognition

πŸ“½An AI for detecting people with webcam

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Webcam Recognition

A tool for detecting who is in front of your webcam

Codacy Badge

Python 3.6

CodeFactor BCH compliance

CII Best Practices

Download

To get the source code, run:

git clone https://github.com/mlabarrere/webcam-recognition.git

Project Structure

Webcam Recognition
β”‚   test_reco.py
β”‚   train_reco.py
β”‚   README.md (To Complete)
β”‚   requirements.txt
β”‚   setup.py (To Do)
β”‚   LICENSE.md
β”‚
└───src
β”‚       β”‚   __init__.py
β”‚       β”‚   lib.py
β”‚  
└───haar
β”‚       β”‚  haarcascade_frontalface_alt.xml
β”‚       β”‚  haarcascade_frontalface_alt2.xml
β”‚       β”‚  haarcascade_frontalface_alt_tree.xml
β”‚       β”‚  haarcascade_frontalface_default.xml
β”‚  
└───data
β”‚       β”‚   You will populate it
β”‚  
└───model
β”‚       β”‚   It will populate on its own

Installing

First, let's install the required libraries, cd to the root of the project where requirements.txt is :

cd yourDirectory/webcam-recognition/

then

pip install -r requirements.txt

Cool, you've got everything ready to run the program

Train your model

The model is based on Haar like features, hence, you need to train your model.

For this, you need to gather pictures of you and your friends (ask them before). Then put all thoses pictures into separated named folders Γ¬nto the data folder. Please, use only common letters (look how I had to remove the Γ© from PΓ©pito).

To train your model to detect PΓ©pito and Paolo, do something like this:

data
└───Pepito
β”‚       β”‚   picture1.jpg
β”‚       β”‚   picture2.png
β”‚       β”‚   picture_with_whatever_name_or_classic_format.jpg
β”‚
└───Paolo
β”‚       β”‚   picture1.jpg
β”‚       β”‚   picture2.png
β”‚       β”‚   picture_with_whatever_name_or_classic_format.jpg

Nice, it seems that you are ready to train your model now.

Ok, then you just have to cd to the root of the repository, and run:

python train_reco.py

The prompt will show you things like:

Preparing data...
Training for Pepito, Paolo               # Check if this is ok
[ INFO:0] Initialize OpenCL runtime...   # You just don't care about it
Data prepared

Training the model...
Training complete

Saving model...
Saving done

Train your model - Best Practices

The thing is, Haar is not Google's top neural networks, hence you need to help him to do his work.

  • Quality over quantity:

    One good picture, like one from a recent ID card, will always be better than ten from your last Project X party.

  • Balance the number of pictures over people to reduce over/under fitting:

    Assume PΓ©pito has 30 pictures to train on, and Paolo only 5, you can be sure the model will say everyone is PΓ©pito.

  • Crop your pictures to avoid loosing training examples:

    If the prompt prints this Impossible to find Paolo, it means that on a picture, he wasn't able to recognise anyone. So there is three main reason of this :

    1. There is multiple faces on this picture
    2. The algorithm cannot detect a face from a weird light
    3. The picture has no background, do not crop the face to make the face filling the picture. Let some air.

    In any cases: you just lost a training example.

  • Turn lights on and show yourself:

    The model will have hard time recognising you in a middle of the night, or if you have changed drastically from your training pictures. Ex : You just shaved your beloved beard, you have no longer a skater's long hair, etc...

  • Avoid twins:

    Well, because... They are twins.

Test your model

You have now the folder model filled with two files:

  1. model.xml : The model :)
  2. dict.pickle : The mapper, because the model can associate only faces with numbers, this dictionary will map numbers to faces.

But you don't have to care about it.

Now, let's see how the model recognizes you:

python test_reco.py

You'll see the webcam fire, and see yourself in a window, with a green box around your face.

Does the model recognize you? If not, you need to train it better, with more and better pictures.

Thanks for reading.

Sorry for the long post, here is a potatoe: πŸ₯”

Author

See also the list of contributors who participated in this project.

License

This project is licensed under the Apache 2 License - see the LICENSE.md file for details

Acknowledgments

About

πŸ“½An AI for detecting people with webcam

License:Apache License 2.0


Languages

Language:Python 100.0%