A computer vision project demonstrating face detection and recognition capabilities using OpenCV and the face_recognition library. This system allows users to upload images, detect faces, and match them against a database of known faces.
- Face Detection: Identifies and locates faces in images using OpenCV
- Face Recognition: Matches detected faces against known faces using face_recognition library
- User-friendly Interface: Simple web interface built with Streamlit
- Database Management: Easily add new people to the recognition database
- Clone this repository:
git clone https://github.com/Assem-ElQersh/Face-Recognition-System.git
cd Face-Recognition-System
- Create a virtual environment (recommended):
python -m venv venv
source venv/bin/activate # On Windows, use: venv\Scripts\activate
- Install dependencies:
pip install -r requirements.txt
-
Install system dependencies (required for face_recognition):
For Ubuntu/Debian:
sudo apt-get install cmake sudo apt-get install libboost-all-dev
For Windows: See detailed instructions on the dlib installation guide
-
Create sample data (test images):
python create_sample_data.py
- Start the web interface:
streamlit run ui/app.py
-
Navigate to the provided URL in your browser (typically http://localhost:8501)
-
Upload an image to detect faces
-
Register new faces by adding labeled images to the data/known_faces directory (one subdirectory per person)
The system includes a script to create sample data automatically. Run python create_sample_data.py
to:
- Create the necessary directory structure
- Download sample face images from the OpenCV repository (if available)
- Generate synthetic face images if downloads fail
The script will populate:
data/known_faces/person1/
anddata/known_faces/person2/
with individual face imagesdata/sample_images/
with group images for testing detection and recognition
If you want to use your own images:
- Place individual face images in the appropriate person folders (e.g.,
data/known_faces/john/image1.jpg
) - Place group/test images in the
data/sample_images/
directory
Face-Recognition-System/
├── README.md # Project documentation
├── QUICKSTART.md # Quick start guide
├── requirements.txt # Dependencies
├── main.py # Main application entry point
├── create_sample_data.py # Script to create sample data
├── face_detector.py # Face detection module
├── face_recognizer.py # Face recognition module
├── utils.py # Utility functions
├── ui/
│ ├── __init__.py
│ ├── app.py # UI application using Streamlit
│ └── components.py # UI components
├── data/
│ ├── known_faces/ # Directory for known face images
│ │ ├── person1/ # Each person gets their own directory
│ │ │ ├── image1.jpg
│ │ │ └── image2.jpg
│ │ └── person2/
│ │ ├── image1.jpg
│ │ └── image2.jpg
│ └── sample_images/ # Sample images for testing
│ ├── group1.jpg
│ └── group2.jpg
└── models/ # Directory for model files (if needed)
In addition to the web interface, you can use the command-line interface:
Face Detection:
python main.py --mode detect --image path/to/image.jpg --output results/output.jpg
Face Recognition:
python main.py --mode recognize --image path/to/image.jpg --output results/output.jpg
Add a Face:
python main.py --mode add_face --image path/to/face.jpg --name "Person Name"
Encode Known Faces:
python main.py --mode encode
- Python 3.7+
- OpenCV
- face_recognition
- dlib
- numpy
- Streamlit
- Add real-time face recognition using webcam
- Implement user authentication system
- Add database integration for storing face encodings
- Improve recognition accuracy with additional algorithms
This project is licensed under the MIT License - see the LICENSE file for details.