This project demonstrates real-time face recognition using OpenCV and the face_recognition
library. The system detects faces from a live camera feed and identifies them based on pre-encoded images.
- Detects faces from live video feed.
- Recognizes known faces based on pre-encoded images.
- Highlights identified faces with bounding boxes and names.
- Python 3.6 or higher
- OpenCV
- face_recognition library
- NumPy
- A working webcam for real-time face detection.
-
Clone this repository:
git clone https://github.com/mohammeduvez29/Facial-Recognition-Model.git cd Facial-Recognition-Model
-
Install required libraries:
pip install opencv-python face_recognition numpy
-
Ensure you have a folder named
images/
in the root directory of the project. Add images of known faces to this folder. Name the images with the corresponding person's name (e.g.,john_doe.jpg
).
- Run the main script:
python main_video.py
- The system will access your webcam, detect faces, and identify known ones.
- Press
ESC
to exit the program.
.
├── main_video.py # Main script for real-time face recognition
├── simple_facerec.py # Helper class for face encoding and recognition
├── images/ # Folder containing known face images
└── README.md # Project documentation
This script:
- Initializes the webcam.
- Loads known face encodings using the
SimpleFacerec
class. - Detects faces in real-time and highlights them with bounding boxes and labels.
This class provides methods to:
- Load and encode images from the
images/
directory. - Detect and identify faces in each frame using the
face_recognition
library.
- Recognized faces will be highlighted with a rectangle and their name displayed below the rectangle.
- Unknown faces will be labeled as "Unknown".
Here is an example of the face recognition output:
Install the following libraries:
opencv-python
face_recognition
numpy
- Error: ModuleNotFoundError: No module named 'face_recognition'
Ensure you have installed theface_recognition
library. On some systems, you may need to installdlib
before installingface_recognition
:pip install dlib pip install face_recognition
- Error: Camera not working
Check your webcam permissions or ensure it is properly connected.
This project is open-source and available under the MIT License.
- OpenCV for real-time image processing.
- face_recognition library for face detection and recognition.
Feel free to fork this repository and submit pull requests to improve the functionality or fix bugs.