This project is a Face Recognition System that allows users to add new faces to a dataset, train a classifier on the dataset, and recognize faces using a pre-trained classifier. It consists of three main Python scripts:
main.py
- The entry point for the system, providing a menu for adding new users, training the classifier, and recognizing faces.dataset_generator.py
- Handles dataset generation by capturing images from the webcam, preprocessing them, and saving them for training.face_recognizer.py
- Recognizes faces using the trained classifier and displays the recognized name and confidence level on the screen.
- Add New User: Capture images of a new user, add their details (name and ID) to the dataset, and update the classifier.
- Train Classifier: Automatically trains the classifier on the new dataset.
- Recognize Face: Uses the webcam to detect and recognize faces in real-time, displaying the recognized name on the screen.
- Python
- OpenCV
- NumPy
- PIL (Pillow)
- Clone the repository:
git clone https://github.com/yourusername/facerecognition.git cd facerecognition
- Install the required Python packages:
pip install opencv-contrib-python numpy pillow
- Download the Haar Cascade XML file for face detection:
- You can download the haarcascade_frontalface_default.xml file from the OpenCv GitHub repository.
- Place the file in the root directory of the project.
- Run the program:
python main.py
main.py
: The main script that provides a command-line interface for adding new users, training the classifier, and recognizing faces.dataset_generator.py
: Handles the dataset generation and training of the classifier.face_recognizer.py
: Performs real-time face recognition using the webcam.user_data.json
: A JSON file that stores user data (name and ID) for recognition purposes.classifier.xml
: The trained classifier file used for face recognition.
-
Add New User:
- Run the script using
python main.py
. - Choose option
1
to add a new user. - Enter the name and ID of the user.
- The system will guide you through capturing 30 images of the user's face. Follow the on-screen instructions.
- The images will be saved, and the classifier will be trained automatically.
- Run the script using
-
Recognize Face:
- Run the script using
python main.py
. - Choose option
2
to recognize a face. - The system will use the webcam to detect and recognize faces in real-time, displaying the name and confidence level on the screen.
- Run the script using
-
Exit:
- Choose option
3
to exit the program.
- Choose option
- The user data (name and ID) is stored in a
user_data.json
file as key-value pairs. The key is the ID, and the value is the name of the user.
- Ensure that your webcam is connected and working properly before running the program.
- The system requires good lighting conditions to perform accurate face recognition.
- The confidence level of recognition depends on the quality and number of images in the dataset.
This project is licensed under the MIT License.
- This project uses the OpenCV library for face detection and recognition.
- The Haar Cascade classifier used in this project is provided by OpenCV.