Overview
A face authentication system built with Rust.
Face Authentication is a modular face authentication system consisting of three main components:
- App - A Rust-based face authentication engine that handles face embedding generation, storage, and user authentication
- Camera Server - A Python FastAPI server that provides camera streaming capabilities with support for multiple camera sources
- Workshop - Educational exercises for learning face recognition concepts and implementation techniques
Slidesβ
Featuresβ
- π― Real-time Face Authentication - Fast face recognition using ConvNeXt models
- πΉ Multiple Camera Sources - Support for OpenCV, libcamera, and custom video streams
- πΎ Local File Storage - Simple JSON-based storage for face embeddings
- π Web API - RESTful camera streaming API with dynamic camera switching
- π§ Easy Configuration - YAML-based configuration for all components
- π Cross-platform - Works on Windows, Linux, and Raspberry Pi
- π Educational Workshop - Step-by-step exercises for learning face recognition
Architectureβ
βββββββββββββββββββ HTTP Stream ββββββββββββββββββββ
β Camera Server β ββββββββββββββββ β Face Auth App β
β (Python) β β (Rust) β
β β β β
β β’ FastAPI β β
β β’ OpenCV β β β’ Embedding Gen β
β β’ libcamera β β β’ Authentication β
βββββββββββββββββββ ββββββββββββββββββββ
β β
βΌ βΌ
βββββββββββββββββββ ββββββββββββββββββββ
β USB Camera β β Local Storage β
β Raspberry Pi β β β’ JSON Files β
β Webcam β β β’ Face Embeddingsβ
βββββββββββββββββββ ββββββββββββββββββββ
Quick Startβ
git clone https://github.com/Wyliodrin/edge-ai-face-auth.git
cd edge-ai-face-auth
cd workshop
cargo build
1. Setup Camera Serverβ
cd ~/WORKSHOP/camera_server
source venv/bin/activate
# Start the camera server
uvicorn camera_stream_api:app --host 0.0.0.0 --port 8000
2. Setup Face Auth Appβ
cd app
# Build the application
cargo build
# Run the application
cargo run
3. Usageβ
-
Register a new user:
- Run the app and type
register - Enter a username
- Look at the camera while the system captures face samples
- Run the app and type
-
Authenticate:
- Type
login - Enter your username
- Look at the camera for authentication
- Type
Componentsβ
Face Auth App (Rust)β
The core authentication engine built with Rust for performance and safety.
Key Features:
- ConvNeXt-based face embedding generation
- Local file storage for face embeddings
- Real-time face capture and processing
- High-performance face matching algorithms
Dependencies:
candle-core&candle-nn- Neural network frameworkreqwest- HTTP client for video streamingimage&minifb- Image processing and display
Configuration:
# config.yaml
storage:
type: "local_file"
local_file:
path: "embeddings.json"
stream:
url: "http://localhost:8000/video_feed"
num_images: 5
interval_millis: 10
model:
name: "timm/convnext_atto.d2_in1k"
Camera Server (Python)β
A FastAPI-based streaming server that provides camera access with multiple source support.
Key Features:
- FastAPI web server with real-time streaming
- OpenCV and libcamera support
- Dynamic camera source switching
- Comprehensive error handling and logging
- Health check and diagnostic endpoints
Dependencies:
fastapi&uvicorn- Web framework and serveropencv-python- Computer vision librarypicamera2- Raspberry Pi camera support (optional)
API Endpoints:
GET /- Server status and camera infoGET /health- Health checkGET /video_feed- Video streamGET /camera_info- Detailed camera configurationGET /switch_camera?source={opencv|libcamera}- Switch camera source
Workshopβ
A collection of progressive exercises designed to teach face recognition concepts and implementation.
Exercises:
- Exercise 01 - Image Processing - Loading and normalizing images for neural networks
- Exercise 02 - Embeddings - Computing face embeddings using ConvNeXt models
- Exercise 03 - Similarity - Implementing cosine similarity for face matching
- Exercise 04 - Storage - Building local file storage for face embeddings
- Exercise 05 - Retrieval - Implementing k-nearest neighbor search
Structure:
- Each exercise includes skeleton code with TODO comments
- Solutions provided for reference and verification
- Documentation and explanations
- Progressive difficulty building core concepts
Running testsβ
cd ex0x..
cargo test
Storageβ
Face embeddings are stored locally in JSON format (embeddings.json by default).
Benefits:
- Simple setup with no external dependencies
- Works offline and is easy to backup
- Human-readable format for debugging
- Suitable for development, testing, and small-scale deployments
Project Structureβ
Face Auth/
βββ app/ # Rust face authentication engine
β βββ src/
β β βββ main.rs # Application entry point
β β βββ config.rs # Configuration management
β β βββ embeddings/ # Face embedding generation
β β βββ storage/ # Storage implementations
β β βββ image_utils/ # Image processing utilities
β βββ config.yaml # App configuration
β βββ Cargo.toml # Rust dependencies
βββ camera_server/ # Python camera streaming server
β βββ camera_stream_api.py # FastAPI application
β βββ requirements.txt # Python dependencies
β βββ config.env # Environment configuration
βββ workshop/ # Workshop exercises
βββ ex01_image_processing/ # Exercise 1: Image loading and normalization
βββ ex02_embeddings/ # Exercise 2: Face embedding generation
βββ ex03_similarity/ # Exercise 3: Cosine similarity computation
βββ ex04_storage_local/ # Exercise 4: Local file storage implementation
βββ ex05_retrieval/ # Exercise 5: k-NN search and retrieval
βββ solution/ # Reference solutions for all exercises
Authentication Issuesβ
-
Poor recognition accuracy:
- Ensure good lighting conditions
- Capture multiple face samples during registration
- Keep face centered and looking at camera
-
Video stream errors:
- Verify camera server is running on correct port
- Check network connectivity between components
Performance Optimizationβ
-
Faster inference:
- Use release build:
cargo run --release - Adjust capture interval in config
- Use release build:
-
Memory usage:
- Limit number of face samples during capture
Licenseβ
This project is licensed under the MIT License - see the individual component READMEs for details.
Acknowledgmentsβ
- Uses Candle framework for neural network inference
- Camera streaming powered by FastAPI
- Image processing with OpenCV and Rust image crate
Supportβ
For issues and questions:
- Review component-specific READMEs in
app/andcamera_server/ - Open an issue in the repository
Face Auth - Secure, fast, and reliable face authentication for modern applications.