This project is a face recognition pipeline that allows for the detection and matching of faces against a pre-existing dataset. The system uses DeepFace, a powerful deep learning library for facial recognition tasks, and supports multiple detector backends.
The project consists of three main components:
- Face Detection: Identifies faces in images using a detection backend (e.g., OpenCV).
- Face Matching: Matches detected faces against a dataset of images.
- Pipeline Execution: Orchestrates the processing of new images to detect and match faces.
project_root/
|-- datasets/ # Dataset of existing face images for matching
|-- new_images/ # Folder containing new images to process
|-- main.py # Main script to run the pipeline
|-- face_detection.py # Module for face detection
|-- face_matching.py # Module for face matching
|-- requirements.txt # Python dependencies
- Python 3.7+
- Required libraries (install via
requirements.txt):
pip install -r requirements.txt
deepfaceopencv-python
- Add new images to the
new_images/folder. - Run the main script:
python main.pyThe script will:
- Detect faces in the images located in the
new_images/folder. - Match detected faces against the dataset in the
dataset/folder. - Print the results, including matched identities or
Unknownif no match is found.
For example, when processing new1.jpg in new_images/, the script might print:
Processing image: new1.jpg
🔍 Matching face 1 in new1.jpg...
✅ Face 1 matches: person1.jpg
Processing image: new2.jpg
⚠ No faces detected in new2.jpg.
The pipeline works as follows:
-
Face Detection:
- Faces are detected in the input images using the OpenCV backend of DeepFace. This involves preprocessing, such as alignment and resizing, to improve detection accuracy.
-
Feature Extraction:
- Detected faces are passed through a pre-trained model (DeepFace) to extract embeddings (numerical feature representations of faces).
-
Face Matching:
- The extracted embeddings are compared against embeddings from the dataset using similarity metrics (cosine similarity).
-
Thresholding:
- A match is considered valid if the distance between embeddings is below a pre-defined threshold (0.68).
- The dataset consists of labeled images stored in the
dataset/folder. - Each subfolder corresponds to a unique individual, e.g.,:
dataset/ |-- person1/ |-- 1.jpg |-- 2.jpg |-- person2/ |-- 1.jpg |-- 2.jpg - Ensure that images are clear and contain identifiable faces.
- The system uses DeepFace’s default pre-trained models (e.g., VGG-Face, Facenet) for feature extraction.
- These models are fine-tuned for face recognition tasks and are downloaded automatically by DeepFace if not already present.
- For a given image, the pipeline outputs the best match or "Unknown" if no match is found.
- The pipeline was tested with a small dataset of 10 individuals, each with 5 images. Results showed:
- Detection Accuracy: 90%
- Matching Accuracy: 85% (with a threshold of 0.68).
To improve accuracy, consider increasing the dataset size and using higher-quality images.
This is the entry point of the project. It orchestrates the detection and matching of faces for new images.
Handles face detection using DeepFace and OpenCV.
Handles matching detected faces against the dataset.
-
No Faces Detected: The system will log a message and skip the image.
-
Matching Errors: If no match is found or an error occurs, the system returns
Unknownfor the face.
-
Enhanced Detection:
- Add support for camera usage
- Improve preprocessing of images to handle different lighting and orientations.
-
Batch Processing:
- Process multiple images simultaneously to improve efficiency.
-
Interactive Reports:
- Generate a summary report (e.g., CSV or HTML) of the matches.
For questions or suggestions, please reach out to the project maintainer.