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.
- โ 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
- 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
This flow avoids build headaches and GUI crashes on Windows:
- Clone the repository
git clone https://github.com/creativepurus/Face_Recognition_Attendance_System.git
cd Face_Recognition_Attendance_System- Create & activate Conda environment
conda create -n face_attend python=3.8 -y
conda activate face_attend- Install core dependencies with conda (dlib, OpenCV, pandas, numpy)
conda install -c conda-forge dlib opencv pandas numpy -y- Install face_recognition with pip (after dlib via conda)
pip install face_recognitionNotes:
- 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.
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')"
Run the attendance system:
python Attendance.pyEnvironment 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.pyHeadless mode:
$env:NO_GUI="1"
python Attendance.py- The webcam opens and starts detecting faces.
- Known faces (from the Images folder) are recognized.
- Attendance is recorded in CSV with:
- Name
- Date
- Time
- Only one entry per person per day is written (de-duplication).
- Press q to quit if running with a window.
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โ).
| 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.
-
Python 3.8 (recommended for face_recognition/dlib)
-
C++ Build Tools (required for manual dlib/face_recognition builds on Windows)
- Microsoft Visual C++ Build Tools
- During install, select โC++ build toolsโ workload, including the recommended defaults.
- Microsoft Visual C++ Build Tools
-
Conda (Anaconda or Miniconda)
- Anaconda Download
(Full distribution) - Miniconda Download
(Minimal installer for conda)
- Anaconda Download
-
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.
- 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-
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.
- 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
Pull requests are welcome! To contribute:
- Fork the repo
- Create a new branch
- Commit changes
- Open a Pull Request
This project is licensed under the MIT License โ feel free to use and modify.
Developed by creativepurus ๐ฅ