A complete, production-ready local face-recognition attendance system for Linux desktop and Raspberry Pi. Runs entirely offline with no cloud APIs, using MediaPipe for face detection and face_recognition for embeddings.
- Live Face Registration: Capture multiple face angles and generate face encodings
- Real-time Face Recognition: Recognize faces from webcam with confidence scores
- Automatic Attendance Logging: Track attendance with timestamp and fee status
- Local Database: All data stored in SQLite (no cloud sync)
- Fee Status Tracking: Green light for paid, red for unpaid
- Duplicate Prevention: Avoid multiple check-ins within time window
- MediaPipe Face Detection: Accurate, lightweight face detection
- dlib ResNet Embeddings: 128-dimensional face encodings via face_recognition library
- Euclidean Distance Matching: Fast face comparison using distance metrics
- Modular Architecture: Separate modules for detection, recognition, database, registration
- Tkinter GUI: Cross-platform desktop interface
- CLI Modes: Command-line interface for headless operation
- Performance Optimized: CPU-friendly processing suitable for Raspberry Pi
Bus-Management/
βββ main.py # Entry point (GUI/CLI)
βββ requirements.txt # Python dependencies
βββ README.md # This file
βββ modules/ # Core modules
β βββ __init__.py
β βββ detection.py # MediaPipe face detection
β βββ recognition.py # Face encoding and matching
β βββ database.py # SQLite operations
β βββ registration.py # Live registration workflow
β βββ attendance.py # Real-time recognition
β βββ utils.py # Utility functions
βββ ui/ # User interface
β βββ main_ui.py # Tkinter GUI
βββ data/ # Data directory
β βββ attendance.db # SQLite database (auto-created)
β βββ students/ # Student data (optional)
β βββ temp/ # Temporary files
βββ logs/ # Log files
βββ system.log # System logs
- OS: Linux (Ubuntu 20.04+ recommended)
- Python: 3.8 or higher
- Webcam: Any USB or integrated webcam
- Dependencies: pip, git
cd ~/Desktop/Github/Bus-Managementpython3 -m venv venv
source venv/bin/activatepip install -r requirements.txtIf you encounter issues with dlib compilation:
# Ubuntu/Debian
sudo apt-get install build-essential cmake pkg-config libopenblas-dev liblapack-dev libx11-dev
pip install face_recognition
# Or install pre-compiled version
pip install face-recognition --no-build-isolation# Test webcam with OpenCV
python3 -c "import cv2; cap = cv2.VideoCapture(0); print('Webcam OK' if cap.isOpened() else 'Webcam NOT found')"python3 main.py
# or
python3 main.py --guipython3 main.py --registerpython3 main.py --recognizepython3 main.py --clipython3 main.py --setupGUI Method:
- Open application β "Register Student" tab
- Enter name, student ID, fee status
- Click "Start Registration"
- Webcam opens - capture face from multiple angles
- Move head left, right, up, down for 5 frames
- System generates and stores 128-D face encodings
CLI Method:
python3 main.py --registerGUI Method:
- Open application β "Recognition" tab
- Adjust confidence threshold (0.6 default)
- Click "Start Recognition"
- Webcam shows live feed:
- Green box: Face recognized + fee paid β
- Red box: Face recognized + fees pending β
- Blue box: Unknown face
- Press 'q' in webcam window to exit
CLI Method:
python3 main.py --recognizeGUI Method:
- Open application β "View Attendance" tab
- Optionally filter by student ID
- Click "Refresh"
- Export to CSV with "Export to CSV"
CLI Method:
python3 main.py --cli
# Select option 3 or 4Update Fee Status:
python3 main.py --cli
# Select option 6
# Enter student ID and new status- Capture: Frame from webcam
- Resize: Reduce size for speed (640px max width)
- Convert: BGR β RGB for MediaPipe
- Detect: MediaPipe face detection
- Extract: Bounding box and crop face region
- Validate: Check face area >= 5000 pixels
- Input: Cropped face image (BGR)
- Model: dlib ResNet-based embeddings (face_recognition)
- Output: 128-dimensional encoding
- Compare: Euclidean distance to stored encodings
- Match: If distance <= threshold (0.6)
- Result: Student ID + confidence score
CREATE TABLE students (
student_id TEXT PRIMARY KEY,
name TEXT NOT NULL,
fee_status TEXT DEFAULT 'unpaid',
registration_date TIMESTAMP,
phone TEXT,
email TEXT
);CREATE TABLE embeddings (
embedding_id INTEGER PRIMARY KEY,
student_id TEXT NOT NULL,
embedding TEXT NOT NULL,
capture_date TIMESTAMP,
quality_score REAL,
FOREIGN KEY (student_id) REFERENCES students(student_id)
);CREATE TABLE attendance (
attendance_id INTEGER PRIMARY KEY,
student_id TEXT NOT NULL,
name TEXT,
check_in_time TIMESTAMP,
fee_status TEXT,
confidence REAL,
device_id TEXT,
FOREIGN KEY (student_id) REFERENCES students(student_id)
);- Lower (0.3-0.4): More lenient, may allow wrong matches
- Default (0.6): Balanced accuracy
- Higher (0.8-1.0): Strict, may reject valid faces
- Number of captures: 5-10 frames per registration
- Capture interval: 0.5 seconds between frames
- Minimum face area: 5000 pixels (to ensure quality)
- Duplicate window: 5 minutes (avoid duplicate attendance)
- Model: HOG (CPU-friendly, good for Raspberry Pi)
- Timeout: 5-10 minutes per session
# Update system
sudo apt update && sudo apt upgrade -y
# Install required packages
sudo apt install -y \
python3-pip \
python3-dev \
build-essential \
cmake \
git \
libopenblas-dev \
liblapack-dev \
libx11-dev \
python3-tk
# Clone repository
cd ~/Desktop/Github
git clone https://github.com/yourusername/Bus-Management.git
cd Bus-Management
# Create virtual environment
python3 -m venv venv
source venv/bin/activate
# Install dependencies
pip install --upgrade pip
pip install -r requirements.txt
# First time setup
python3 main.py --setup
# Run application
python3 main.pysudo apt install -y \
python3-pip \
python3-dev \
build-essential \
cmake \
libopenblas-dev \
liblapack-dev \
libx11-dev \
python3-tk
# Rest same as Ubuntu- Raspberry Pi 4 (4GB+ RAM recommended)
- Raspberry Pi OS (Bullseye or later)
- Pi Camera Module v2 or USB webcam
- SD card (64GB+ for comfort)
# Update system
sudo apt update && sudo apt upgrade -y
# Install dependencies
sudo apt install -y \
python3-pip \
python3-dev \
libjasper-dev \
libtiff-dev \
libjasper1 \
libharfbuzz0b \
libwebp6 \
libtiff5 \
libatlas-base-dev \
liblapack-dev \
libopenblas-dev \
libblas-dev \
libharfbuzz0b \
libwebp6 \
python3-tk
# Increase swap (important for compilation)
sudo dphys-swapfile swapoff
sudo sed -i 's/CONF_SWAPSIZE=100/CONF_SWAPSIZE=2048/' /etc/dphys-swapfile
sudo dphys-swapfile swapon
# Clone and setup
cd ~/
git clone https://github.com/yourusername/Bus-Management.git
cd Bus-Management
python3 -m venv venv
source venv/bin/activate
# Install with no cache (slower but works on Pi)
pip install --no-cache-dir -r requirements.txt
# Reset swap when done
sudo dphys-swapfile swapoff
sudo sed -i 's/CONF_SWAPSIZE=2048/CONF_SWAPSIZE=100/' /etc/dphys-swapfile
sudo dphys-swapfile swapon
# First run
python3 main.py --setup
python3 main.py &- Face Detection: ~15-20 FPS (640x480)
- Face Recognition: ~8-10 FPS (with 100 stored embeddings)
- Combined: ~8 FPS real-time recognition
- Registration: ~2-5 seconds per face encoding
- Face Detection: ~5-8 FPS (640x480)
- Face Recognition: ~2-3 FPS (with 50 stored embeddings)
- Combined: ~2-3 FPS real-time recognition
- Registration: ~5-10 seconds per face encoding
- β No Cloud: All processing local
- β No Internet: Works fully offline
- β No API Keys: No external dependencies
- β Data Privacy: All embeddings stored locally
- β No Biometric Sync: No cloud backup of faces
- β Open Source: Transparent code, audit-able
1. Custom Face Detection:
# Modify modules/detection.py
class CustomDetector(FaceDetector):
def detect_faces(self, frame):
# Your custom detection logic
pass2. Custom Recognition Model:
# Modify modules/recognition.py
class CustomRecognizer(FaceRecognizer):
def get_face_encoding(self, face_image):
# Your custom encoding logic
pass3. Custom Database Backend:
# Create modules/database_custom.py
class CustomDatabase(AttendanceDatabase):
# Override methods as needed- β Raspberry Pi 4 support (see setup guide)
- β Pi Camera Module support
- β Servo gate control (GPIO via RPi.GPIO)
- β GPS tracking (via GPS module)
- β Mobile app sync (optional cloud)
- β Multi-camera support
- β Mask detection
- β Temperature scanning integration
# List connected cameras
ls -la /dev/video*
# Test with OpenCV
python3 -c "import cv2; print(cv2.VideoCapture(0).isOpened())"# Verify virtual environment is active
source venv/bin/activate
# Reinstall dependencies
pip install -r requirements.txt- Ensure good lighting
- Face should be 50x50 pixels minimum
- Try moving closer to camera
- Check camera is working with:
v4l2-ctl --all # requires v4l-utils
- Reduce frame resolution to 480x360
- Reduce confidence threshold
- Use fewer stored embeddings (limit to 100)
- Enable GPU acceleration (if available)
# Pre-compiled wheel
pip install dlib --prefer-binary
# Or use conda
conda install -c conda-forge dlib| Package | Purpose | Why Used |
|---|---|---|
| opencv-python | Video capture & frame processing | Industry standard |
| mediapipe | Face detection | Lightweight, accurate, CPU-friendly |
| face-recognition | Face embeddings (dlib ResNet) | Pre-trained, production-ready |
| numpy | Numerical operations | Core for embeddings |
| psutil | System monitoring | Resource tracking |
| tkinter | GUI | Built-in, cross-platform |
| sqlite3 | Database | Built-in, lightweight |
This project is provided as-is for educational and commercial use.
Contributions welcome! Please follow:
- PEP 8 code style
- Add docstrings to functions
- Test on both Linux desktop and Raspberry Pi
- Submit pull requests with detailed descriptions
For issues and questions:
- Check troubleshooting section
- Review code comments and docstrings
- Check system logs in
logs/system.log
- Core face detection (MediaPipe)
- Face recognition (face_recognition)
- SQLite database
- Tkinter GUI
- CLI interface
- Linux support
- Raspberry Pi optimizations
- Pi Camera support
- GPIO/Servo control
- Multi-camera setup
- Mask detection
- Temperature integration
- Initial release
- Core face detection and recognition
- SQLite database with full CRUD
- Tkinter GUI with 5 main tabs
- CLI modes and menu
- Linux desktop support
- Comprehensive documentation
- Raspberry Pi 4 support guide
Built with β€οΈ for local, offline, privacy-respecting attendance tracking