A real-time face recognition application that captures video from a webcam, detects faces in each frame, matches them against a directory of known reference images, and overlays the recognized name and confidence score on the live feed.
- Language: Python 3.9+
- Computer vision: OpenCV (
opencv-python) - Face detection & encoding:
face_recognition(dlib under the hood) - Numerical: NumPy
- Packaging:
pyproject.tomlwith asrc/layout
.
├── faces/ # Reference images (one face per file, filename = label)
├── src/
│ └── face_recognition_app/
│ ├── __init__.py
│ ├── app.py # Entry point (main function)
│ ├── config.py # Environment-driven settings
│ ├── helpers.py # Confidence calculation utility
│ └── recognizer.py # FaceRecognition class
├── main.py # Thin launcher for running without installation
├── pyproject.toml
├── requirements.txt
├── .env.example
├── .gitignore
└── README.md
-
Clone the repository:
git clone https://github.com/T0MYAMMM/learn-simple-face-recognition.git cd learn-simple-face-recognition -
Create and activate a virtual environment:
python -m venv .venv source .venv/bin/activate # Linux / macOS .venv\Scripts\activate # Windows
-
Install dependencies:
pip install -r requirements.txt
Or install the package itself (editable mode):
pip install -e . -
(Optional) Copy the environment template and adjust values:
cp .env.example .env
-
Add reference photos to the
faces/directory. Each file should contain a single clear face. The filename (without extension) is used as the label.
Run the application directly:
python main.pyOr, after installing the package, use the console script:
face-recognition-appA window will open showing the webcam feed with bounding boxes, recognized
names, and confidence percentages. Press q to exit.
Configurable environment variables (see .env.example):
| Variable | Default | Description |
|---|---|---|
FACES_DIR |
faces |
Directory containing reference images |
CAMERA_INDEX |
0 |
Camera device index for cv2.VideoCapture |
FACE_MATCH_THRESHOLD |
0.6 |
Maximum distance considered a match (0.0 - 1.0) |
FRAME_SCALE |
0.25 |
Frame downscale factor used before encoding |
- Add an automated test suite with sample images and CI integration.
- Support multiple reference images per person and average their encodings.
- Persist face encodings to disk to avoid re-encoding on every startup.
- Provide a CLI subcommand to enroll new faces interactively from the webcam.
- Add GPU acceleration via
dlibCUDA builds for higher frame rates. - Replace the OpenCV window with a web UI (FastAPI + WebRTC) for remote use.
- Add logging and metrics instead of
printstatements. - Containerize the application with Docker for reproducible deployments.