FaceRecognition.mp4
This project is a local face recognition prototype based on webcam input.
The application allows you to:
- register a person from the webcam
- save the registered face locally
- start live face recognition
- compare the detected face with the registered ones
To run the project you need:
- Python 3
pip- a working webcam
- webcam permissions enabled for the terminal or editor you are using
Before running ./setup.sh, make sure that Python 3 is already installed on your system and that pip is available through python3.
You can verify this with:
python3 --version
python3 -m pip --versionIf both commands return a valid version, you can continue with the setup script.
If python3 is not installed, you must install it before running the project.
If you use Homebrew, install Python with:
brew install pythonThen verify the installation:
python3 --version
python3 -m pip --versionOn Debian/Ubuntu-based systems:
sudo apt update
sudo apt install python3 python3-pipThen verify the installation:
python3 --version
python3 -m pip --versionOn Fedora:
sudo dnf install python3 python3-pipThen verify the installation:
python3 --version
python3 -m pip --versionOn Arch Linux:
sudo pacman -S python python-pipThen verify the installation:
python3 --version
python3 -m pip --versionBefore running the project, these Python libraries must be installed:
opencv-python==4.10.0.84Used for webcam access, live video windows, face detection, keyboard handling inside the OpenCV window, and image saving.numpy==1.24.4Used for numerical operations and for computing and comparing face descriptors.matplotlib==3.7.5Present in the project requirements because it was used by the original simulation part of the repository.scipy==1.10.1Present in the project requirements because it was used by the original simulation/statistical part of the repository.
When installing these packages, pip may also install additional dependencies required by them.
If you want to install everything manually, use:
python3 -m pip install -r requirements.txtThe requirements.txt file currently contains:
matplotlib==3.7.5
numpy==1.24.4
opencv-python==4.10.0.84
scipy==1.10.1
If you want to install the libraries one by one, the commands are:
python3 -m pip install matplotlib
python3 -m pip install scipy
python3 -m pip install opencv-python==4.10.0.84numpy is also installed because it is required by these libraries and by the project itself.
To simplify setup, the repository includes a script:
./setup.shThis script:
- moves into the project folder
- creates the folders needed by the project
- installs all Python dependencies from
requirements.txt
The expected execution flow is:
python3 --version
python3 -m pip --version
./setup.shThe folders created are:
.mplconfig.cacheplotsdata/facesOUTPUT
To start the application quickly, use:
./run.shThis script:
- moves into the project folder
- creates the required local folders if they are missing
- starts the application with:
python3 main.pyIf you do not want to use the script, you can also run the program manually:
python3 main.pyAfter starting the application, the main menu shows:
1. Start real face recognition0. Exit
- Run the program
- Enter
1 - In the next menu choose
1to register a new face - Type the person's name in the terminal
- The webcam window opens
- Click on the webcam window to make sure it has focus
- When the face is correctly framed, press
SPACEorENTER - The face sample is saved locally
- Run the program
- Enter
1 - In the next menu choose
2 - The webcam opens and the program tries to recognize registered faces live
- Run the program
- Enter
1 - In the next menu choose
3 - The program prints the list of people already registered
The keyboard controls must be used directly inside the webcam window, not in the terminal.
SPACEcaptures the current faceENTERcaptures the current faceqexitsQexitsESCexits
qexitsQexitsESCexits
If the window does not respond to the keyboard:
- click on the webcam window
- try again
- if needed, stop the program from the terminal with
Ctrl+C
Registered faces are stored locally in:
data/face_db.jsondata/faces/
To check which Python libraries are installed:
python3 -m pip listTo show only the main libraries used for this project:
python3 -m pip list | grep -E 'matplotlib|scipy|opencv-python|numpy'To inspect package details and installation path:
python3 -m pip show matplotlib scipy opencv-python numpy- This is a local prototype, not a production-grade biometric security system.
- The recognition pipeline currently uses OpenCV face detection plus handcrafted face descriptors.
- Good lighting and a stable frontal face position improve recognition quality.
This section explains exactly what is inside setup.sh and run.sh, and what each instruction means.
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
mkdir -p .mplconfig .cache plots data/faces OUTPUT
python3 -m pip install -r requirements.txt
echo
echo "Setup completed."
echo "Run the app with:"
echo "python3 main.py"#!/usr/bin/env bashTells the operating system to execute the script usingbash.set -euo pipefailEnables a safer shell mode.-eStops the script immediately if a command fails.-uStops the script if an undefined variable is used.pipefailMakes pipelines fail if any command inside them fails.ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"Computes the absolute path of the directory where the script is located.${BASH_SOURCE[0]}Refers to the current script file.dirname "${BASH_SOURCE[0]}"Extracts the directory that contains the script.cd ... && pwdMoves into that directory and prints its absolute path.ROOT_DIR=...Stores that absolute path in the variableROOT_DIR.- Example:
If
setup.shis located at/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition/setup.sh, then:${BASH_SOURCE[0]}becomes/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition/setup.sh,dirname "${BASH_SOURCE[0]}"becomes/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition, andROOT_DIRis finally set to/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition. cd "$ROOT_DIR"Moves into the root folder of the project.mkdir -p .mplconfig .cache plots data/faces OUTPUTCreates the directories used by the project if they do not already exist.mkdirCreates directories.-pPrevents errors if a directory already exists and creates parent directories when needed..mplconfigUsed bymatplotlibfor configuration and cache files..cacheGeneric local cache directory.plotsDirectory originally used for generated plot files.data/facesDirectory used to store saved face samples.OUTPUTDirectory originally used by the legacy simulation output.python3 -m pip install -r requirements.txtInstalls all required Python packages listed inrequirements.txt.python3 -m pipRunspipthrough the current Python 3 interpreter.installTellspipto install packages.-r requirements.txtReads the list of packages from therequirements.txtfile.echoPrints a blank line.echo "Setup completed."Prints a confirmation message.echo "Run the app with:"Prints an instruction line.echo "python3 main.py"Prints the manual command used to start the application.
#!/usr/bin/env bash
set -euo pipefail
ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
cd "$ROOT_DIR"
mkdir -p .mplconfig .cache plots data/faces OUTPUT
python3 main.py#!/usr/bin/env bashTells the operating system to execute the script usingbash.set -euo pipefailEnables a safer shell mode.-eStops the script if a command fails.-uStops the script if an undefined variable is used.pipefailMakes pipelines fail if any command inside them fails.ROOT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"Computes the absolute path of the directory whererun.shis located.${BASH_SOURCE[0]}Refers to the current script.dirname "${BASH_SOURCE[0]}"Extracts the folder containing the script.cd ... && pwdMoves there and prints the absolute path.ROOT_DIR=...Saves that path into the variableROOT_DIR.- Example:
If
run.shis located at/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition/run.sh, then:${BASH_SOURCE[0]}becomes/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition/run.sh,dirname "${BASH_SOURCE[0]}"becomes/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition, andROOT_DIRis finally set to/Users/simoneremoli/PYTHON_VIRTUAL_WORLD/airport-face-recognition. cd "$ROOT_DIR"Moves into the project root.mkdir -p .mplconfig .cache plots data/faces OUTPUTCreates the local folders required by the project if they are missing.python3 main.pyStarts the application.python3Launches the Python 3 interpreter.main.pyRuns the main entry point of the project.