Face Recognition and Tracking System
Advanced, modular system for real-time face recognition and optional camera tracking, combining machine learning, computer vision, and embedded hardware.
Project Gallery
Electronic circuit
Project Overview
Face Recognition and Turntable Tracking System
An advanced, modular system for real-time face recognition and automatic face tracking using a motorized turntable. The project combines machine learning, computer vision, and embedded hardware to keep faces centered in the camera view by physically moving the camera mount.
š Project Summary
This project detects and recognizes faces in real-time video streams using state-of-the-art machine learning models. It features a motorized turntable (servo-driven, ESP32-controlled) that automatically rotates to follow and center faces in the camera view. The system is designed for extensibility, performance, and ease of use, and demonstrates the integration of software and hardware for intelligent movement and tracking.
š Quick Start
- Install dependencies:
pip install opencv-python numpy insightface scikit-learn requests tqdm onnxruntime - Prepare data:
- Create a directory:
data/known_faces - Add subfolders for each person, with their face images inside
- Create a directory:
- Train models:
python train.py --interactive - Run recognition and tracking:
python recognize.py --recognition-method knn --target "Person Name" - (Optional) Enable tracking hardware:
cd esp32-servo-controller pio run -t upload
š Project Structure
face-recognition-system/
train.py, recognize.py # Main scripts
src/ # Core modules (dataset, detector, recognizer, utils)
data/
known_faces/ # Training images (per person)
... # Model outputs, embeddings, etc.
esp32-servo-controller/ # Firmware for camera tracking hardware
š¼ļø Hardware & Program Overview
| Electronic Schema | Turntable Photo |
|---|---|
Turntable Hardware:
- The turntable is powered by a servo motor and controlled by an ESP32 microcontroller running a web server.
- The camera is mounted on the turntable, allowing it to rotate horizontally to follow faces.
- The ESP32 receives movement commands from the recognition software over Wi-Fi (HTTP requests), adjusting the turntable position in real time.
Tracking Logic:
- The recognition software detects faces and identifies the target person in each frame.
- The position of the target face is compared to the center of the camera frame.
- If the face is off-center (outside a deadzone), the software calculates the direction and speed needed to re-center the face.
- An HTTP command is sent to the ESP32 controller, which rotates the turntable accordingly.
- The ESP32 servo controller receives the command, sets the servo speed and direction, and moves the turntable.
- This closed-loop system keeps the target face centered automatically.
⨠Features
- High-accuracy face detection (InsightFace)
- Multiple recognition methods: KNN, Naive Bayes, Decision Tree, SVM, MLP
- Interactive training with camera
- Data augmentation (rotation, brightness, blur)
- Real-time performance metrics (FPS, recognition rate)
- Automatic turntable movement: Motorized camera mount rotates to follow faces
- Closed-loop face tracking: Keeps target centered using live feedback
- ESP32-based servo controller: Fast, wireless hardware integration
š§āš» Training Process
- Data Collection:
- Use
train.py --interactiveto capture images with the camera, or use existing images. - Each person:
data/known_faces/{person_name}
- Use
- Face Detection & Embedding:
- InsightFace detects faces and extracts 512D embeddings for each face.
- Data Augmentation:
- Images are rotated, brightness-adjusted, and blurred to increase dataset size and robustness.
- Model Training:
- Embeddings and names are collected.
- Multiple classifiers (KNN, Naive Bayes, Decision Tree, MLP, SVM) are trained.
- Models and scaler are saved for later use.
šµļø Recognition & Tracking
- Camera & Initialization:
- USB camera is initialized and frames are captured.
- Face detector and recognition model are loaded.
- Frame Processing:
- Frames are processed in real time, in a separate thread for performance.
- Performance metrics (FPS, recognition rate) are calculated.
- Face Detection & Recognition:
- Faces are detected and embeddings extracted.
- Each face is recognized using the selected model; confidence scores are calculated.
- Bounding boxes, names, and facial landmarks are drawn on the frame.
- Turntable Tracking Logic:
- If a target person is specified, their position is tracked.
- The position of the target face is compared to the center of the frame.
- If the face is off-center (outside a deadzone), the direction and speed for the turntable are calculated.
- An HTTP command is sent to the ESP32 controller to rotate the turntable and re-center the face.
- The ESP32 receives the command and moves the servo accordingly.
- This allows for hands-free, automatic following of people, ideal for security, robotics, or interactive installations.
āļø Command-Line Usage
Train interactively:
python train.py --interactive
Train on existing files:
python train.py
Augment data:
python train.py --augment
Run recognition:
python recognize.py --recognition-method knn --target "Person Name"
Tracking (optional):
python recognize.py --recognition-method knn --target "Person Name" --servo-url http://192.168.4.1
š License
This project is open source. See LICENSE for details.


