Skip to main content

Overview

A face authentication system built with Rust.

Face Authentication is a modular face authentication system consisting of three main components:

  1. App - A Rust-based face authentication engine that handles face embedding generation, storage, and user authentication
  2. Camera Server - A Python FastAPI server that provides camera streaming capabilities with support for multiple camera sources
  3. Workshop - Educational exercises for learning face recognition concepts and implementation techniques

Slides​

download the 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​

  1. Register a new user:

    • Run the app and type register
    • Enter a username
    • Look at the camera while the system captures face samples
  2. Authenticate:

    • Type login
    • Enter your username
    • Look at the camera for authentication

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 framework
  • reqwest - HTTP client for video streaming
  • image & 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 server
  • opencv-python - Computer vision library
  • picamera2 - Raspberry Pi camera support (optional)

API Endpoints:

  • GET / - Server status and camera info
  • GET /health - Health check
  • GET /video_feed - Video stream
  • GET /camera_info - Detailed camera configuration
  • GET /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​

  1. Poor recognition accuracy:

    • Ensure good lighting conditions
    • Capture multiple face samples during registration
    • Keep face centered and looking at camera
  2. Video stream errors:

    • Verify camera server is running on correct port
    • Check network connectivity between components

Performance Optimization​

  1. Faster inference:

    • Use release build: cargo run --release
    • Adjust capture interval in config
  2. 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/ and camera_server/
  • Open an issue in the repository

Face Auth - Secure, fast, and reliable face authentication for modern applications.