This project implements a real-time face recognition system using a camera, the OpenCV library, the face_recognition library, and the K-Nearest Neighbors (KNN) algorithm. The system was developed as an academic project in the field of artificial intelligence.
- Python 3.x
- OpenCV
- face_recognition
- NumPy
projekat-knn/
├── main.py # Recording and encoding user faces
├── rec.py # Real-time face recognition
├── haarcascade_frontalface_default.xml # Face detection model
├── data/ # Folder with encoded .npy files
├── README.md # Project description
├── requirements.txt # List of required Python libraries
- Recording and encoding user faces
- Saving feature vectors to a
.npyfile - Loading the database of known faces
- Face recognition using a manually implemented KNN algorithm
- Displaying the person's name above the detected face
- Install the required libraries:
pip install -r requirements.txt
- First run
loadData.pyto capture and save face samples. - Then run
recSystem.pyfor face recognition.
.npyfiles are automatically created for each user and saved in the./data/folder.- Each file contains 20 encoded face samples.
- The
haarcascade_frontalface_default.xmlfile must be in the same folder as the scripts. - The application uses the default webcam (
device 0).
Below are images illustrating the application running in real time:
These images show an example where the application detects a user's face via the camera and successfully identifies the person based on previously recorded samples using the KNN algorithm.
Milutin Jovanović
Faculty of Electronic Engineering, University of Niš
2024/2025 – Artificial Intelligence

