Skip to content

Latest commit

 

History

History
522 lines (421 loc) · 16.2 KB

File metadata and controls

522 lines (421 loc) · 16.2 KB

Face Recognition Attendance System - Complete Project Explanation

📚 Table of Contents

  1. What is This Project?
  2. Why We Built This?
  3. How Does It Work?
  4. Key Features Explained
  5. Technical Architecture
  6. User Roles & Their Functions
  7. Security Features
  8. Smart Features
  9. Technologies Used
  10. Future Scope

What is This Project?

This is an AI-powered Face Recognition Attendance System built specifically for Invertis University. It replaces the traditional manual attendance system with an automated, secure, and intelligent solution.

Main Purpose:

  • Eliminate Proxy Attendance: Students cannot mark attendance for their friends
  • Save Time: No need for manual roll calls or paper registers
  • Real-time Tracking: Teachers and admins can see attendance instantly
  • Smart Insights: Students know exactly how many classes they need to attend

The Problem We Solved:

  1. Proxy Attendance: Friends marking attendance for absent students
  2. Time Wastage: 10-15 minutes wasted in every class for roll call
  3. Manual Errors: Wrong entries, lost registers, calculation mistakes
  4. No Insights: Students don't know their attendance status until it's too late
  5. Location Fraud: Students marking attendance from outside campus

Why We Built This?

Traditional System Problems:

  • Manual Roll Call: Teacher calls each name, students respond - wastes 10-15 minutes
  • Paper Registers: Can be lost, damaged, or tampered with
  • Proxy Attendance: Very common - friends say "present" for absent students
  • No Real-time Data: Attendance calculated at end of semester
  • Location Issues: Students can mark attendance from anywhere

Our Solution Benefits:

  • 30 seconds: Total time to mark attendance for entire class
  • 100% Accurate: Face recognition ensures the right person is present
  • Real-time: Instant attendance updates for everyone
  • Smart Predictions: AI tells students how many classes they need
  • Campus-only: GPS ensures students are physically on campus

How Does It Work?

Step-by-Step Process:

1. Registration Phase (One-time setup)

Student registers → Enters details → Scans face → Face data stored as numbers
  • Student creates account with email, name, college ID
  • System captures face using webcam
  • AI converts face into 128 numbers (face descriptor)
  • Important: We don't store photos, only mathematical numbers
  • These numbers are unique for each person, like a fingerprint

2. Teacher Creates Session

Teacher logs in → Selects course → Clicks "Start Session" → GPS location captured
  • Teacher opens the app in classroom
  • Selects which course and section
  • System captures teacher's GPS location (classroom location)
  • Session becomes "LIVE" for students
  • Sets duration (30 min, 60 min, etc.)

3. Student Marks Attendance

Student opens app → Sees live session → Clicks "Mark Attendance" → Face scan + GPS check → Attendance marked
  • Student sees which sessions are currently live
  • Clicks on their class session
  • System checks:
    • ✅ Is student's face matching registered face?
    • ✅ Is student within 100 meters of classroom?
    • ✅ Is only one face in camera?
    • ✅ Is face real (not a photo)?
  • If all checks pass → Attendance marked ✓

4. Real-time Updates

Attendance marked → Teacher sees count increase → Admin sees system stats → Student sees updated percentage
  • Teacher's dashboard shows live count: "15/50 students marked"
  • Admin sees total attendance across all classes
  • Student sees updated attendance percentage instantly

Key Features Explained

1. Face Recognition Technology

How it works:

  • Uses AI library called face_recognition
  • Converts face into 128-dimensional vector (128 numbers)
  • Compares new face with stored face using mathematical distance
  • If distance < 0.6 → Face matches ✓
  • If distance > 0.6 → Different person ✗

Why it's secure:

  • Can't be fooled by photos (liveness detection)
  • Can't be fooled by videos (texture analysis)
  • Requires real person with real face movements

Example:

Stored Face: [0.234, 0.567, 0.123, ... 128 numbers]
New Face:    [0.235, 0.568, 0.124, ... 128 numbers]
Distance:    0.45 → MATCH! ✓

2. Geofencing (GPS Location Check)

What is Geofencing?

  • Creates a virtual boundary around campus
  • Only allows attendance if student is inside boundary

How it works:

Campus Center: Latitude 28.6139, Longitude 77.2090
Allowed Radius: 100 meters
Student Location: Latitude 28.6145, Longitude 77.2095
Distance Calculation: 67 meters → INSIDE! ✓

Formula Used:

  • Haversine formula (calculates distance between two GPS points)
  • If distance ≤ 100 meters → Allowed
  • If distance > 100 meters → Blocked

Why it's important:

  • Students can't mark attendance from home
  • Students can't mark attendance from hostel
  • Must be physically present in campus

3. Liveness Detection

What is Liveness Detection?

  • Ensures the face is real, not a photo or video

Checks performed:

  1. Blink Detection: Checks if eyes blink
  2. Head Movement: Checks if head moves slightly
  3. Texture Analysis: Checks if it's real skin or printed paper
  4. Single Face Check: Ensures only one person in frame

Why it's needed:

  • Prevents using printed photos
  • Prevents using phone/tablet with friend's photo
  • Prevents using pre-recorded videos

4. Smart Attendance Predictions

What it does:

  • Tells students exactly how many classes they need to attend

Example:

Course: Data Structures
Total Sessions: 40
Attended: 25
Current Percentage: 62.5%
Target: 75%

Calculation:
Need to attend: 10 more classes
Message: "Attend next 10 classes to reach 75%"

Formula:

Required Classes = (Target% × Total - 100 × Attended) / (100 - Target%)
Required Classes = (75 × 40 - 100 × 25) / (100 - 75)
Required Classes = (3000 - 2500) / 25
Required Classes = 500 / 25 = 20 classes

Status Indicators:

  • 🟢 Good: ≥75% attendance
  • 🟡 Warning: 65-74% attendance
  • 🔴 Critical: <65% attendance

5. Attendance Streak Tracking

What is Streak?

  • Counts consecutive days of attendance
  • Motivates students to maintain consistency

Example:

Monday: Present ✓ → Streak = 1 🔥
Tuesday: Present ✓ → Streak = 2 🔥🔥
Wednesday: Present ✓ → Streak = 3 🔥🔥🔥
Thursday: Absent ✗ → Streak = 0 (Reset)

Benefits:

  • Gamification makes attendance fun
  • Students compete for longer streaks
  • Encourages regular attendance

6. Real-time Dashboard Updates

How it works:

  • Uses AJAX (Asynchronous JavaScript)
  • Fetches new data from server every 30 seconds
  • Updates page without reloading

Example:

Time 10:00 AM: 10 students marked
Time 10:01 AM: 15 students marked (auto-updated)
Time 10:02 AM: 20 students marked (auto-updated)

Benefits:

  • Teacher sees live progress
  • No need to refresh page manually
  • Real-time decision making

7. Kiosk Mode

What is Kiosk Mode?

  • Hands-free attendance marking
  • Teacher places tablet/laptop at classroom entrance
  • Students scan face while entering

How it works:

1. Teacher starts session
2. Opens kiosk mode on tablet
3. Places tablet at door
4. Students scan face while entering
5. Automatic attendance marking

Benefits:

  • No need for students to use phones
  • Faster attendance marking
  • Works like office biometric system

Technical Architecture

System Components:

┌─────────────────────────────────────────────────────────────┐
│                        USER INTERFACE                        │
│  (HTML, CSS, JavaScript, Bootstrap - Glassmorphism Design)  │
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                      FLASK WEB SERVER                        │
│         (Python Flask - Handles all requests)                │
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                    BUSINESS LOGIC LAYER                      │
│  • Face Recognition (face_recognition library)               │
│  • Geofencing (Haversine formula)                           │
│  • Liveness Detection (OpenCV)                              │
│  • Smart Predictions (Custom algorithms)                     │
└─────────────────────────────────────────────────────────────┘
                              ↓
┌─────────────────────────────────────────────────────────────┐
│                      DATABASE LAYER                          │
│  • SQLite (Development)                                      │
│  • PostgreSQL (Production ready)                             │
│  • Firebase (Optional cloud sync)                            │
└─────────────────────────────────────────────────────────────┘

Database Schema:

Main Tables:

  1. User: Stores student/teacher/admin details
  2. Course: Stores course information
  3. ClassSession: Stores live class sessions
  4. SessionAttendance: Stores who attended which session
  5. Enrollment: Links students to courses
  6. AttendanceAttempt: Logs all attendance attempts (success/failure)
  7. Timetable: Stores class schedule

Relationships:

User (1) ──→ (Many) SessionAttendance
Course (1) ──→ (Many) ClassSession
ClassSession (1) ──→ (Many) SessionAttendance
User (Many) ←──→ (Many) Course (through Enrollment)

User Roles & Their Functions

1. Student Role

What Students Can Do:

  • ✅ Register account and scan face
  • ✅ View live class sessions
  • ✅ Mark attendance with face + GPS
  • ✅ See attendance percentage for each course
  • ✅ Get smart predictions (classes needed)
  • ✅ View attendance history and calendar
  • ✅ Track attendance streak
  • ✅ See failed attendance attempts
  • ✅ Re-scan face if needed

Student Dashboard Features:

  • Course-wise attendance breakdown
  • Overall attendance percentage
  • Live sessions with countdown timer
  • Smart insights with predictions
  • Attendance streak counter
  • Calendar view of attendance

2. Teacher Role

What Teachers Can Do:

  • ✅ Create and manage courses
  • ✅ Start live class sessions
  • ✅ View real-time attendance counts
  • ✅ See session roster (who attended, who didn't)
  • ✅ Close sessions manually
  • ✅ Export attendance as CSV
  • ✅ Create timetable entries
  • ✅ Launch kiosk mode
  • ✅ View failed attendance attempts

Teacher Dashboard Features:

  • Live session monitoring
  • Real-time attendance counts
  • Session cards with statistics
  • Course overview with enrollment
  • Timetable management
  • CSV export functionality

3. Admin Role

What Admins Can Do:

  • ✅ View system-wide statistics
  • ✅ Manage all users (create, edit, delete)
  • ✅ Create courses and assign teachers
  • ✅ Bulk import students via CSV
  • ✅ Assign sections to students
  • ✅ Change user roles
  • ✅ Clear face data
  • ✅ View 7-day attendance heat grid
  • ✅ Monitor low attendance students
  • ✅ Generate sessions from timetable

Admin Dashboard Features:

  • Total students, teachers, courses
  • Active sessions count
  • Today's attendance count
  • Department-wise statistics
  • 7-day attendance heat grid
  • User management table
  • Bulk operations

Security Features

1. Password Security

  • Uses Scrypt hashing algorithm
  • Passwords are never stored in plain text
  • Even admins can't see user passwords

2. CSRF Protection

  • Every form has CSRF token
  • Prevents cross-site request forgery attacks
  • Tokens expire after session ends

3. Rate Limiting

  • Limits number of requests per minute
  • Prevents brute force attacks
  • Protects server from overload

4. Session Management

  • Secure session cookies
  • Auto-logout after inactivity
  • Session hijacking prevention

5. Input Validation

  • All user inputs are validated
  • SQL injection prevention
  • XSS attack prevention

6. Audit Logging

  • Every attendance attempt is logged
  • Stores IP address, user agent, device hash
  • Failed attempts are tracked
  • Helps in fraud detection

Smart Features

1. Automated Session Generation

  • Reads timetable entries
  • Auto-creates sessions 30 minutes before class
  • No manual session creation needed
  • Runs every 5 minutes

2. Auto-close Expired Sessions

  • Automatically closes sessions after end time
  • Runs every 2 minutes
  • Keeps database clean

3. Low Attendance Alerts

  • Sends email to students with <75% attendance
  • Runs daily at 8 AM
  • Shows exactly how many classes needed
  • Course-wise breakdown

4. Real-time Notifications

  • Toast notifications for all actions
  • Success/error messages
  • Non-intrusive design

5. Responsive Design

  • Works on desktop, tablet, mobile
  • Touch-friendly interface
  • Optimized for all screen sizes

Technologies Used

Backend:

  • Python 3.9+: Main programming language
  • Flask: Web framework
  • SQLAlchemy: Database ORM
  • Flask-Login: User authentication
  • APScheduler: Background task scheduling

Frontend:

  • HTML5: Structure
  • CSS3: Styling with Glassmorphism
  • JavaScript: Interactivity
  • Bootstrap 5: Responsive framework
  • Font Awesome: Icons

AI/ML Libraries:

  • face_recognition: Face detection and recognition
  • dlib: Face landmark detection
  • OpenCV: Image processing
  • NumPy: Numerical computations

Database:

  • SQLite: Development database
  • PostgreSQL: Production ready
  • Firebase: Optional cloud sync

Other Tools:

  • Git: Version control
  • Gunicorn: Production server
  • Nginx: Reverse proxy (production)

Future Scope

Planned Features:

  1. Mobile App: Native Android/iOS apps
  2. QR Code Attendance: Faster marking option
  3. Voice Commands: "Mark my attendance"
  4. Blockchain: Immutable attendance records
  5. AI Analytics: Predict student performance
  6. Parent Portal: Parents can view attendance
  7. SMS Alerts: Low attendance SMS
  8. Multi-language: Hindi, regional languages
  9. Offline Mode: Works without internet
  10. Biometric Integration: Fingerprint backup

Scalability:

  • Can handle 10,000+ students
  • Cloud deployment ready
  • Load balancing support
  • Database sharding possible

Project Statistics

  • Total Lines of Code: ~15,000+
  • Number of Files: 50+
  • Database Tables: 12
  • API Endpoints: 25+
  • User Roles: 3 (Student, Teacher, Admin)
  • Security Features: 10+
  • Smart Features: 8+

Conclusion

This Face Recognition Attendance System is a complete, production-ready solution that:

  • ✅ Eliminates proxy attendance
  • ✅ Saves time (30 seconds vs 15 minutes)
  • ✅ Provides real-time insights
  • ✅ Uses AI for smart predictions
  • ✅ Ensures campus-only attendance
  • ✅ Offers beautiful, modern UI
  • ✅ Scales to thousands of users

Built with ❤️ by Team AstraTech for Invertis University