Skip to content

A Python-based attendance system that uses Face Recognition to automatically mark attendance by detecting and recognizing faces from a live webcam feed.

License

Notifications You must be signed in to change notification settings

creativepurus/Face_Recognition_Attendance_System

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

18 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ‘จ๐ŸŽ“ Facial Recognition Attendance System (Windows 11 Ready)

A Python-based attendance system that uses Face Recognition to automatically mark attendance by detecting and recognizing faces from a live webcam feed.

  • This README includes an installer-like setup specifically tuned for Windows 11 (64-bit), Conda environments, and common OpenCV/dlib pitfalls.

๐Ÿš€ Features

  • โœ… Real-time face detection and recognition using OpenCV and dlib
  • โœ… Automatically logs recognized faces into an Excel/CSV attendance file
  • โœ… One-entry-per-person-per-day de-duplication
  • โœ… Robust Windows 11 setup with GUI and headless modes
  • โœ… Simple and lightweight Python-based solution
  • โœ… Well-suited for educational institutions and offices

๐Ÿ› ๏ธ Tech Stack

  • Python 3.8+ (Recommended: 3.8, for dlib/face_recognition compatibility)
  • Conda โ€“ Preferred environment manager
  • OpenCV โ€“ Camera input & image processing (Win32 HighGUI preferred on Windows)
  • dlib โ€“ Face encoding model (via conda)
  • face_recognition โ€“ High-level API for face encodings & matching (via pip)
  • pandas โ€“ Attendance logging
  • CSV (and optional per-day rotation) โ€“ Output files

๐Ÿ“ฆ Installation (Windows 11 x64 - Recommended)

This flow avoids build headaches and GUI crashes on Windows:

  1. Clone the repository
git clone https://github.com/creativepurus/Face_Recognition_Attendance_System.git
cd Face_Recognition_Attendance_System
  1. Create & activate Conda environment
conda create -n face_attend python=3.8 -y
conda activate face_attend
  1. Install core dependencies with conda (dlib, OpenCV, pandas, numpy)
conda install -c conda-forge dlib opencv pandas numpy -y
  1. Install face_recognition with pip (after dlib via conda)
pip install face_recognition

Notes:

  • Install dlib via conda first, then install face_recognition via pip to avoid ABI conflicts.
  • If using a Qt-built OpenCV that crashes with โ€œCould not find the Qt platform plugin 'windows'โ€, prefer an OpenCV build with Win32 HighGUI (typical with conda). Headless mode is also available (see below).

Optional: verify OpenCV build (Win32 HighGUI recommended on Windows)

python -c "import cv2; print(cv2.__version__); print(cv2.getBuildInformation().splitlines()[0])"

You should see a GUI section indicating Win32 UI (older builds) or a working Qt6 runtime. If Qt errors occur, see Troubleshooting.


๐Ÿ“ฆ Alternative: Environment file (environment.yml)

Use this Pre-Configured environment for a Reproducible setup.

How to use it

  • Create the environment:
    • conda env create -f environment.yml
  • Activate:
    • conda activate face_attend
  • Verify key imports:
    • python -c "import cv2, dlib, face_recognition, pandas, numpy as np; print('OK')"

โ–ถ๏ธ Usage

Run the attendance system:

python Attendance.py

Environment variables (optional):

  • CAMERA_INDEX: Select camera (default 0)
  • FRAME_SCALE: Downscale for performance (default 0.25)
  • DETECTION_MODEL: hog (default) or cnn
  • DISTANCE_THRESHOLD: Recognition acceptance threshold (default 0.50)
  • ATTENDANCE_FILE: CSV path (default Attendance.csv)
  • DAILY_ROTATION: โ€œ1โ€ to write per-day CSV (Attendance_YYYY-MM-DD.csv)
  • VIDEO_BACKEND: โ€œdefaultโ€, โ€œmsmfโ€ (Media Foundation), or โ€œdshowโ€ (DirectShow)
  • NO_GUI: โ€œ1โ€ to run headless (no window, useful for servers/kiosks)

Examples (PowerShell):

$env:VIDEO_BACKEND="msmf"           # Use Media Foundation on Windows 11
$env:DISTANCE_THRESHOLD="0.55"      # Slightly more permissive
$env:DAILY_ROTATION="1"             # Per-day CSV files
python Attendance.py

Headless mode:

$env:NO_GUI="1"
python Attendance.py

Workflow

  1. The webcam opens and starts detecting faces.
  2. Known faces (from the Images folder) are recognized.
  3. Attendance is recorded in CSV with:
    • Name
    • Date
    • Time
  4. Only one entry per person per day is written (de-duplication).
  5. Press q to quit if running with a window.

๐Ÿ“‚ Project Structure

Face_Recognition_Attendance_System/
โ”‚โ”€โ”€ Attendance.py             # Main application file (robust Windows handling)
โ”‚โ”€โ”€ test_face.py              # Script to test face encoding/detection
โ”‚โ”€โ”€ test_installation.py      # Script to test setup and installation
โ”‚โ”€โ”€ environment.yml           # Conda environment/dependencies file (optional)
โ”‚โ”€โ”€ Attendance.csv            # File where attendance is saved (default)
โ”‚โ”€โ”€ README.md                 # Documentation
โ”‚โ”€โ”€ LICENSE                   # Project license
โ”‚โ”€โ”€ .gitignore                # Git ignore file
โ”‚โ”€โ”€ Images/                   # Folder containing known faces

Enrollment guidance:

  • Put 1โ€“3 clear, frontal images per person into Images/.
  • Each image must contain exactly one face. Multi-face or no-face images are skipped.
  • Filenames become labels (e.g., โ€œAnand_Photo_1.jpgโ€ โ†’ โ€œAnand Photo 1โ€).

๐Ÿ“Š Example Attendance Output

Name Date Time
Obama 2025-08-18 09:32:14
Sample 1 2025-08-18 09:35:02

With DAILY_ROTATION=1, files are written as Attendance_YYYY-MM-DD.csv.


๐Ÿ›ก๏ธ Requirements

These are the official and most reliable sources for each requirement.


โš™๏ธ Windows 11 Tips and Backend Notes

  • Prefer conda-forge OpenCV (installed via conda) so HighGUI works out-of-the-box.

  • If the camera is flaky to open, set a specific backend:

    • VIDEO_BACKEND=msmf (Media Foundation, recommended on Windows 10/11)
    • VIDEO_BACKEND=dshow (DirectShow, alternative)
  • The app includes:

    • Camera warm-up frames (reduces initial black frames)
    • Robust RGB conversion (cv2.cvtColor)
    • Defensive handling of transient invalid frames (skips gracefully)
  • Headless mode (NO_GUI=1) avoids GUI entirely and is reliable on servers/kiosks.


๐Ÿงช Quick Self-Tests

  • OpenCV HighGUI test:
python -c "import cv2, numpy as np; img=np.zeros((200,300,3),dtype=np.uint8); cv2.namedWindow('t'); cv2.imshow('t',img); cv2.waitKey(800); cv2.destroyAllWindows()"
  • Camera backend switch:
$env:VIDEO_BACKEND="msmf"
python Attendance.py
  • Adjust threshold if genuine matches show as Unknown:
$env:DISTANCE_THRESHOLD="0.55"
python Attendance.py

๐Ÿงน Troubleshooting

  • Qt platform plugin โ€œwindowsโ€ error (cv2.imshow crash):

    • Use an OpenCV build with Win32 HighGUI (typical with conda).
    • Or run headless: NO_GUI=1.
    • Avoid mixing pip OpenCV with conda OpenCV in the same env.
  • compute_face_descriptor() or DLL errors:

    • Ensure dlib was installed via conda first, then install face_recognition via pip.
  • No face detected in enrollment images:

    • Use clear, front-facing, unfiltered images with one face only.
  • Duplicate daily entries:

    • The app prevents duplicates by Name+Date. If running multiple instances, consider centralizing CSV or using a database.

๐Ÿ”ฎ Future Improvements

  • Multi-camera support
  • Cloud database integration (Firebase / Supabase)
  • Web dashboard for attendance monitoring
  • SMS/Email notifications
  • GUI enrollment tool and encoding cache for faster startup

๐Ÿ™Œ Contribution

Pull requests are welcome! To contribute:

  1. Fork the repo
  2. Create a new branch
  3. Commit changes
  4. Open a Pull Request

๐Ÿ“œ License

This project is licensed under the MIT License โ€“ feel free to use and modify.


๐Ÿ‘จ๐Ÿ’ป Author

Developed by creativepurus ๐Ÿ”ฅ

๐Ÿ‘‰๐Ÿป LinkedIn | GitHub

About

A Python-based attendance system that uses Face Recognition to automatically mark attendance by detecting and recognizing faces from a live webcam feed.

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages