Skip to content

AnwarXahid/face_recog_livliness

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Face Recognition with Liveness Detection

An automated employee attendance system using face recognition with anti-spoofing capabilities for my previous company. This system eliminates the need for fingerprint scanners or manual attendance marking by providing secure, real-time face authentication with liveness detection.

Overview

This project implements a comprehensive face recognition system that includes:

  • Real-time face detection and recognition
  • Liveness detection to prevent spoofing attacks
  • Pose and emotion detection capabilities
  • Automated attendance tracking
  • Web-based interface using Flask

Requirements

  • Python: 3.6+ (Originally developed with Python 3.6/3.7)
  • Operating System: Windows, macOS, or Linux
  • Hardware: Webcam, GPU recommended for real-time processing
  • Dependencies: Listed in requirements.txt

Features

  • Face Recognition: Accurate employee identification using trained facial models
  • Anti-Spoofing: Liveness detection to prevent photo/video spoofing attempts
  • Real-time Processing: Live webcam-based attendance marking
  • Pose Detection: Employee pose analysis for better authentication
  • Emotion Recognition: Optional emotion detection capabilities
  • Web Interface: Flask-based web application for easy deployment
  • Automated Training: Tools for training custom face recognition models

Project Structure

face_recog_livliness/
├── datasets/                           # Training datasets and employee photos
├── libfaceid/                         # Core face recognition library
├── models/                            # Trained ML models and weights
├── templates/                         # HTML templates for web interface
├── final_basic_real_time_face_recog.py    # Basic real-time face recognition
├── final_fr_with_liveliness.py           # Face recognition with liveness detection
├── final_real_time_pose_emotion.py       # Pose and emotion detection
├── final_training_model.py               # Model training script
├── training.py                           # Training utilities
├── xahid_training.py                     # Custom training implementation
├── testing_webcam.py                     # Webcam testing utilities
├── testing_webcam_flask.py              # Flask web interface testing
├── testing_webcam_livenessdetection.py  # Liveness detection testing
├── xahid_blinking.py                     # Blink detection for liveness
├── xahid_demo.py                         # Demo implementation
└── requirements.txt                      # Python dependencies

Installation

Prerequisites

  • Python 3.6 or higher (Python 3.7+ recommended)
  • pip package manager
  • Webcam or camera device

Setup Instructions

  1. Clone the repository:

    git clone https://github.com/AnwarXahid/face_recog_livliness.git
    cd face_recog_livliness
  2. Create virtual environment (recommended):

    # For Windows
    python -m venv face_recog_env
    face_recog_env\Scripts\activate
    
    # For macOS/Linux
    python3 -m venv face_recog_env
    source face_recog_env/bin/activate
    
  3. Install dependencies:

    pip install -r requirements.txt
  4. Set up datasets:

    • Place employee photos in the datasets/ directory
    • Organize photos by employee ID or name
    • Ensure good quality, well-lit photos for better recognition

Usage

Training the Model

  1. Prepare your dataset:

    python training.py
  2. Train the face recognition model:

    python final_training_model.py
  3. Custom training (alternative):

    python xahid_training.py

Running the System

  1. Basic Face Recognition:

    python final_basic_real_time_face_recog.py
  2. Face Recognition with Liveness Detection:

    python final_fr_with_liveliness.py
  3. With Pose and Emotion Detection:

    python final_real_time_pose_emotion.py
  4. Web Interface:

    python testing_webcam_flask.py

Testing Components

  • Test webcam functionality:

    python testing_webcam.py
  • Test liveness detection:

    python testing_webcam_livenessdetection.py
  • Test blink detection:

    python xahid_blinking.py
  • Run demo:

    python xahid_demo.py

Key Components

Liveness Detection

The system implements multiple liveness detection methods:

  • Blink Detection: Monitors eye blinks to ensure a live person
  • Face Movement: Tracks subtle facial movements
  • Depth Analysis: Analyzes facial depth to prevent photo spoofing

Face Recognition

  • Uses deep learning models for accurate face encoding
  • Supports multiple employees with high accuracy
  • Real-time processing for instant attendance marking

Anti-Spoofing Features

  • Photo spoofing prevention
  • Video replay attack detection
  • 3D mask detection capabilities

Configuration

  1. Camera Setup: Ensure your webcam is properly configured
  2. Model Paths: Update model paths in configuration files
  3. Employee Database: Set up employee records with corresponding face encodings
  4. Attendance Logging: Configure attendance database/file storage

Performance Optimization

  • GPU Support: Enable GPU acceleration for faster processing
  • Model Optimization: Use optimized models for real-time performance
  • Threading: Implement multi-threading for concurrent processing

Security Features

  • Anti-Spoofing: Multiple layers of spoofing detection
  • Secure Storage: Encrypted storage of face encodings
  • Access Control: Role-based access to attendance data
  • Audit Trail: Complete logging of attendance events

Deployment

For production deployment:

  1. Hardware Requirements:

    • Good quality webcam (HD recommended)
    • Adequate lighting conditions
    • GPU recommended for real-time processing
  2. Server Deployment:

    • Deploy Flask application on production server
    • Configure proper database for attendance records
    • Set up automated backup systems

Troubleshooting

Common Issues:

  • Camera not detected: Check camera permissions and connections
  • Poor recognition: Improve lighting conditions or retrain models
  • False spoofing alerts: Adjust liveness detection sensitivity
  • Performance issues: Consider hardware upgrades or model optimization

About

Real-time face recognition with liveness (spoof) detection for remote KYC and fintech security.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors