This project demonstrates a simple face recognition system using the K-Nearest Neighbors (KNN) algorithm. KNN is a supervised machine learning algorithm that classifies new data points based on the majority class of their nearest neighbors. In this case, the algorithm will be used to recognize faces by comparing them to a database of known faces.
The system consists of the following steps:
-
Data Collection: Collect a dataset of images containing faces of known individuals. Ensure that the images have consistent lighting and pose.
-
Feature Extraction: Extract numerical features from each image. Common features include Haar-like features or deep learning-based features.
-
Training: Train the KNN classifier using the extracted features and corresponding labels (identity of the person in each image).
-
Recognition: To recognize a new face, extract its features and find the K nearest neighbors in the training dataset. The class of the majority of these neighbors is considered the predicted identity of the new face.
To use the system, follow these steps:
-
Clone the repository.
-
Create a virtual environment (venv or virtualenv) in the project directory.
-
Activate the virtual environment.
-
Install the required dependencies.
- Run
pip install -r requirements.txt
.
- Run
-
Adding New Faces
- Run
add-new-face.py
: - Locate the script named
add-new-face.py
. Execute this script to launch the program. It will typically activate your computer's camera.
- Run
-
Face Detection and Naming:
- When prompted, enter a name for the person whose face is being detected. This name will be associated with the captured face image for future recognition.
- Face the camera so that your face is centered within the frame. The script should detect your face.
-
Face Recognition
- Run
face-recognition.py
: - Locate the script responsible for face recognition, likely named
face-recognition.py
. Execute this script to start the program. It will typically activate your computer's camera.
- Run
-
Real-Time Recognition:
- Face the camera again. The script should detect faces in the camera view. If a recognized face is detected, the script should display the corresponding name associated with that face.
The system requires the following dependencies:
- numpy
- opencv-python
- scikit-learn
- scipy
This project is licensed under the MIT License. See the LICENSE file for more details.
For more details and tutorials, visit the website: DocsAllOver.
Follow us on:
and visit our website to know more about our tutorials and blogs.