This project is a Face Recognition Attendance System built using Django for the backend and OpenCV and face-recognition libraries for facial matching. The system captures video frames from a webcam, processes each frame to detect and recognize faces, and marks attendance if a match is found. This solution is ideal for tracking attendance in environments like offices, classrooms, and other restricted access areas.
- Real-time face detection and recognition using OpenCV.
- Automatic attendance marking and logging in the database.
- CSRF-protected endpoints for secure frame data submission.
- Easy setup with a web-based interface for live camera streaming.
- Backend: Django
- Frontend: HTML, JavaScript, Tailwindcss
- Libraries: OpenCV, face-recognition, Numpy
- Database: SQLite (default, can be configured for other databases)
Python 3.8>>DjangoOpenCV(cv2)openpyxlpandasplaysoundpickleface-recognitionlibraryNumpy
To install dependencies, you can use the following:
pip install django opencv-python face-recognition numpy pandas openpyxl playsound pickleDetectionAlgorithms- Encapsulates recognision algorithms attendance handlersmiddleware- Implements Ratelimit and other security measuresmigrations- Encapsulates database handling for clockins and account managementstatic/- Static files (CSS, JavaScript)templates/- HTML templates for web interfacemedia- Temporary store of enrollment data during enrollment phrase, also stores csv & xlsx regisry for clockin detailsmanage.py- Django management script
-
Clone the repository:
git clone https://github.com/skye-cyber/FRASystem.git cd FRASystem -
Set up Django: Initialize the database and run migrations:
python manage.py makemigrations python manage.py migrate
-
Prepare Face Encodings:
- Store face encodings of authorized individuals by running an initial script or manually adding to the
encodings.picklefile in the project. - Use the
face_recognitionlibrary to generate encodings from a dataset of images of authorized individuals.
- Store face encodings of authorized individuals by running an initial script or manually adding to the
-
Run the Server: Start the Django development server:
python manage.py runserver
-
Access the Web Interface: Open a browser and navigate to
http://127.0.0.1:8000/to access the attendance system.
-
Login & Signup page You must Register your account inorder to access the site
-
Home page This is the welcome page for the project, under the navigation menu you access your profile, Enroll to attendance system
-
Profile A display of the user details, including Enrollment status From the menu you can access:
Clockin Pageinorder to clockinDelete Accountbeware this is permanentUenroll from the clockin systemyour account will still be available but you have no acess to clockin, this will delete your previous clockin data
-
Enrolling Upon loading the page, the camera starts automatically (you may need to grant permissions). Atmost 3 snaps are taken and encoded for recognision. Your photos are nolonger stored after encoding they are deleted permanently.
-
Clocking in: Upon loading the page, the camera starts automatically (you may need to grant permissions). The camera captures frames, and each frame is processed to detect faces. If a recognized face is detected, attendance is marked and logged in the system.
-
View Attendance Logs: Attendance records are stored in the database and can be accessed through the Django admin panel or an additional route for attendance logs.
- /process_frames/ - Receives frames from the client for face processing and returns the result.
- /mark_attendance/ - Processes and logs attendance data upon successful face recognition.
The following snippet captures frames and sends them to the Django server:
async function sendFrameToDjango(frameData) {
const csrftoken = getCookie('csrftoken'); // Implement getCookie function to retrieve the CSRF token
await fetch('/process_frames/', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
'X-CSRFToken': csrftoken
},
body: 'frame=' + encodeURIComponent(frameData)
});
}This view processes incoming frames and matches them with stored face encodings:
@csrf_exempt
def process_frames(request):
if request.method == 'POST':
frame_data = request.POST.get('frame', '')
# Process frame data and perform face recognition
return JsonResponse({'status': 'success'})
return JsonResponse({'error': 'Invalid request'}, status=400)- CSRF Token Missing: Ensure the CSRF token is correctly passed in each POST request. Implement
getCookieto retrieve CSRF tokens from cookies. - Camera Access Issues: Check browser permissions for camera access and ensure secure context (HTTPS) if using on a server.
- Implement role-based access for different user types.
- Add support for multiple cameras.
- Enable reporting and analytics for attendance data.
This project is licensed under the MIT License.