A robust, web-based Face Attendance System deployed on Debian 12. This project uses FastAPI for the backend and face_recognition (dlib) for state-of-the-art face detection.
It features a Client-Side Camera architecture, allowing the server to process video feeds from any connected client (laptop/mobile) via a web browser, ensuring the server doesn't need a physical webcam attached.
- Live Face Recognition: Detects faces in real-time via the browser webcam.
- Automatic Attendance: Logs recognized names with timestamps to
attendance.csv. - Client-Side Capture: Works on remote servers (VPS/Cloud) by using the client's browser camera.
- REST API: Upload images programmatically to identify faces and mark attendance.
- Visual Feedback: Draws bounding boxes and names on the live video feed.
Before installing the Python libraries, you must install the system dependencies required to compile dlib and opencv.
sudo apt-get update
sudo apt-get install -y python3-pip python3-venv cmake libopenblas-dev liblapack-dev libx11-dev libgtk-3-dev-
Clone the repository:
git clone https://github.com/yourusername/face-attendance.git cd face-attendance -
Create a Virtual Environment:
python3 -m venv venv source venv/bin/activate -
Install Python Dependencies:
pip install fastapi uvicorn[standard] numpy opencv-python face_recognition python-multipart
-
Create Directory Structure:
mkdir known_faces
Modern browsers (Chrome, Firefox, Safari) block camera access on insecure HTTP connections (unless using localhost). Since this runs on a server (e.g., 192.168.x.x), you must use HTTPS.
Generate a self-signed certificate in the project root:
openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365 -nodesPress Enter through the prompts.
- Take a clear photo of the person you want to recognize.
- Rename the file to the person's name (e.g.,
Elon Musk.jpg,Bill Gates.png). - Place the file inside the
known_faces/directory. - Restart the server to load the new faces.
Activate your environment and run the app:
source venv/bin/activate
python3 main.pyThe server will start on port 8000 with SSL enabled.
- Open your web browser.
- Navigate to:
https://<YOUR_SERVER_IP>:8000- Example:
https://192.168.21.18:8000
- Example:
- Security Warning: You will see a "Potential Security Risk" warning because the certificate is self-signed.
- Chrome: Click Advanced -> Proceed to...
- Firefox: Click Advanced -> Accept the Risk and Continue.
- Permissions: Click Allow when the browser asks for Camera access.
You can trigger recognition by uploading a file programmatically.
Endpoint: POST /api/recognize_from_file
Example using cURL:
curl -X POST "https://localhost:8000/api/recognize_from_file?file_path=/home/user/test_image.jpg" -k(Note: -k is used to ignore SSL warnings for self-signed certs)
.
├── main.py # Application entry point
├── attendance.csv # Auto-generated attendance log
├── key.pem # SSL Private Key
├── cert.pem # SSL Certificate
├── known_faces/ # Directory for storing reference images
│ ├── Person A.jpg
│ └── Person B.png
└── README.md
"Waiting for camera..." / navigator.mediaDevices is undefined
- Cause: You are accessing the site via
http://instead ofhttps://. - Fix: Ensure you generated the SSL certificates and are accessing the URL with
https://.
"Can't open camera by index" (Server Logs)
- Cause: The server is trying to open a USB camera that doesn't exist.
- Fix: Ensure you are using the updated
main.pythat relies on the Client-Side browser camera, notcv2.VideoCapture(0).