Project File Ai Based Attendence
Project File Ai Based Attendence
BILASPUR (C.G.)
ACKNOWLEDGEMENT
I owe a great thanks to many people who helped me during writing this paper.
DHANANJAY SAHU
Department of Computer Science & Information Technology
Guru Ghasidas Vishwavidyalaya,
Bilaspur (C.G.), 495009
ABSTRACT
Table of Contents
1. Introduction
2. Overview
3. Key Components
- 3.1 Face Detection
- 3.2 Feature Extraction
- 3.3 Face Matching
4. Functionalities
- 4.1 Automatic Attendance Tracking
- 4.2 Fraud Prevention
- 4.3 User Interface
- 4.4 Reporting and Analytics
5. Implementation Details
- 5.1 Hardware Requirements
- 5.2 Software Development
- 5.3 Integration
- 5.4 Testing and Validation
6. Applications
- 6.1 Educational Institutions
- 6.2 Workplaces
- 6.3 Security and Surveillance
7. Code and Working
-7.1 Code
-7.2 Directory Structure
-7.3 Working
8. Conclusion
9. Future Enhancements
10. References
Chapter – 1
INTRODUCTION
INTRODUCTION
In today's fast-paced world, the need for efficient and
accurate attendance tracking systems is paramount,
especially in educational institutions, workplaces, and
various organizational settings. Traditional methods of
attendance tracking, such as manual sign-in sheets or
swipe cards, are not only time-consuming but also
susceptible to errors and fraudulent practices like buddy
punching.
Chapter – 2
OVERVIEW
OVERVIEW
The project aims to develop a facial recognition-based
attendance management system using computer vision
techniques and web technologies. Traditional attendance
tracking methods often suffer from inefficiencies and
inaccuracies, leading to time-consuming processes and
potential errors. This system offers a modern solution to
streamline the attendance management process in various
settings such as educational institutions, workplaces, and
security systems.
Key Objectives:
1. Efficiency: Automate the attendance tracking
process to save time and resources for both
administrators and attendees.
2. Accuracy: Utilize facial recognition technology to
ensure precise attendance records without manual
intervention.
3. Security: Enhance security measures by verifying
the identity of individuals through biometric
authentication.
4. User-Friendly Interface: Provide an intuitive and
easy-to-use interface for administrators and end-users.
Key Components:
The system comprises several key components working
together seamlessly to achieve its objectives:
Chapter – 4
FUNCTIONALITIES
FUNCTIONALITIES
4.1 Automatic Attendance Tracking
-Real-time Recognition: Utilizes facial recognition technology
to automatically detect and identify individuals present in a
given environment.
- Attendance Logging: Records attendance data in a
structured format, including timestamps and individual
identification.
- Efficient Tracking: Eliminates the need for manual
attendance taking, reducing administrative burden and
potential errors.
- Instant Feedback: Provides immediate feedback to users
regarding their attendance status upon recognition.
Chapter – 5
IMPLEMENTATION DETAILS
IMPLEMENTATION DETAILS
5.1 Hardware Requirements
- Camera: Requires a camera or webcam capable of capturing
high-quality images for facial recognition.
- Processing Unit: Needs a computing device (e.g., laptop,
desktop, or server) with sufficient processing power to perform
real-time facial recognition tasks.
- Storage: Sufficient storage space to store captured images,
facial templates, and attendance data.
5.3 Integration
- Face Detection and Recognition: Integrates face detection
and recognition algorithms into the system using OpenCV
libraries and custom machine learning models.
- Web Application Development: Develops a web-based
interface using Flask framework to interact with the attendance
management system.
- Database Integration: Integrates database management
systems to store and retrieve user information, attendance
records, and system configurations.
- Testing and Debugging: Conducts thorough testing and
debugging to ensure the reliability and accuracy of the
system's functionality.
Chapter – 6
APPLICATIONS
APPLICATIONS
6.1 Educational Institutions
- Automated Attendance Tracking: Streamlines
attendance management processes for students and
faculty members, reducing administrative workload
and potential errors.
- Efficient Monitoring: Enables real-time monitoring
of attendance records, allowing educators to identify
patterns and trends in student attendance.
- Enhanced Security: Improves campus security by
accurately tracking individuals' presence and
identifying unauthorized access attempts.
6.2 Workplaces
- Time and Attendance Management: Facilitates
automated time and attendance tracking for
employees, optimizing workforce management and
payroll processes.
- Remote Work Support: Supports remote or flexible
work arrangements by providing a secure and reliable
attendance tracking solution accessible from
anywhere.
- Compliance Monitoring: Helps organizations
ensure compliance with labour regulations and policies
by maintaining accurate attendance records.
Chapter – 7
The script also allows you to add new students to the system.
Usage:
1. Run the script and wait for it to open a webcam window.
2. Look into the webcam and ensure that the face of the student you want
to add is within the frame.
3. Press the "Start" button to start capturing images.
4. Once the required number of images have been captured, the script
will attempt to identify the student.
5. If the student is successfully identified, their name will be added
to the attendance list.
6. You can repeat steps 2-5 for each student you want to add.
7. Once you're done, press the "Stop" button to close the webcam and
view the attendance list.
Note:
1. The script requires a trained model to identify faces. If no model is
found, the script will prompt you to add a face.
2. The model can be trained using the "Train Model" button.
3. The script saves the attendance data in a CSV file, which can be
viewed and edited manually.
"""
import cv2
import os
from flask import Flask, request, render_template
from datetime import date
from datetime import datetime
import numpy as np
from sklearn.neighbors import KNeighborsClassifier
import pandas as pd
import joblib
app = Flask(__name__)
nimgs = 10
imgBackground=cv2.imread("background.png")
datetoday = date.today().strftime("%m_%d_%y")
datetoday2 = date.today().strftime("%d-%B-%Y")
face_detector =
cv2.CascadeClassifier('haarcascade_frontalface_default.xml')
if not os.path.isdir('Attendance'):
os.makedirs('Attendance')
if not os.path.isdir('static'):
os.makedirs('static')
if not os.path.isdir('static/faces'):
os.makedirs('static/faces')
if f'Attendance-{datetoday}.csv' not in os.listdir('Attendance'):
with open(f'Attendance/Attendance-{datetoday}.csv', 'w') as f:
f.write('Name,Roll,Time')
def totalreg():
return len(os.listdir('static/faces'))
def extract_faces(img):
try:
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
face_points = face_detector.detectMultiScale(gray, 1.2, 5,
minSize=(20, 20))
return face_points
except:
return []
def identify_face(facearray):
model = joblib.load('static/face_recognition_model.pkl')
return model.predict(facearray)
def train_model():
faces = []
labels = []
userlist = os.listdir('static/faces')
for user in userlist:
for imgname in os.listdir(f'static/faces/{user}'):
img = cv2.imread(f'static/faces/{user}/{imgname}')
resized_face = cv2.resize(img, (50, 50))
faces.append(resized_face.ravel())
labels.append(user)
faces = np.array(faces)
knn = KNeighborsClassifier(n_neighbors=5)
knn.fit(faces, labels)
joblib.dump(knn, 'static/face_recognition_model.pkl')
def extract_attendance():
df = pd.read_csv(f'Attendance/Attendance-{datetoday}.csv')
names = df['Name']
rolls = df['Roll']
times = df['Time']
l = len(df)
return names, rolls, times, l
def add_attendance(name):
username = name.split('_')[0]
userid = name.split('_')[1]
current_time = datetime.now().strftime("%H:%M:%S")
df = pd.read_csv(f'Attendance/Attendance-{datetoday}.csv')
if int(userid) not in list(df['Roll']):
with open(f'Attendance/Attendance-{datetoday}.csv', 'a') as f:
f.write(f'\n{username},{userid},{current_time}')
def getallusers():
userlist = os.listdir('static/faces')
names = []
rolls = []
l = len(userlist)
for i in userlist:
name, roll = i.split('_')
names.append(name)
rolls.append(roll)
@app.route('/')
def home():
names, rolls, times, l = extract_attendance()
return render_template('home.html', names=names, rolls=rolls,
times=times, l=l, totalreg=totalreg(), datetoday2=datetoday2)
@app.route('/start', methods=['GET'])
def start():
names, rolls, times, l = extract_attendance()
ret = True
cap = cv2.VideoCapture(0)
while ret:
ret, frame = cap.read()
if len(extract_faces(frame)) > 0:
(x, y, w, h) = extract_faces(frame)[0]
cv2.rectangle(frame, (x, y), (x+w, y+h), (86, 32, 251), 1)
cv2.rectangle(frame, (x, y), (x+w, y-40), (86, 32, 251), -
1)
face = cv2.resize(frame[y:y+h, x:x+w], (50, 50))
identified_person = identify_face(face.reshape(1, -1))[0]
add_attendance(identified_person)
cv2.rectangle(frame, (x,y), (x+w, y+h), (0,0,255), 1)
cv2.rectangle(frame,(x,y),(x+w,y+h),(50,50,255),2)
cv2.rectangle(frame,(x,y-40),(x+w,y),(50,50,255),-1)
cv2.putText(frame, f'{identified_person}', (x,y-15),
cv2.FONT_HERSHEY_COMPLEX, 1, (255,255,255), 1)
cv2.rectangle(frame, (x,y), (x+w, y+h), (50,50,255), 1)
imgBackground[162:162 + 480, 55:55 + 640] = frame
cv2.imshow('Attendance', imgBackground)
if cv2.waitKey(1) == 27:
break
cap.release()
cv2.destroyAllWindows()
names, rolls, times, l = extract_attendance()
return render_template('home.html', names=names, rolls=rolls,
times=times, l=l, totalreg=totalreg(), datetoday2=datetoday2)
if __name__ == '__main__':
app.run(debug=True)
Directory Structure
7.2WORKING
FOLLOW THE URL
Conclusion
Conclusion
In conclusion, the developed facial recognition-based
attendance management system offers an efficient and
accurate solution for automating attendance tracking processes
in various environments. By leveraging advanced computer
vision techniques and web technologies, the system addresses
the shortcomings of traditional attendance management
methods, providing benefits such as:
FUTURE
ENHANCEMENTS
FUTURE ENHANCEMENTS
9.1 Enhanced Recognition Algorithms
- Deep Learning Models: Explore the use of deep learning models such
as Convolutional Neural Networks (CNNs) for more robust and accurate
face recognition.
- Feature Extraction Techniques: Implement advanced feature
extraction techniques to capture finer details and improve recognition
performance.
Chapter – 10
REFERENCES
REFERENCES
1. Lienhart, R., & Maydt, J. (2002). An extended set of Haar-like
features for rapid object detection. In Proceedings of the
International Conference on Image Processing (Vol. 1, pp.
900-903). IEEE.
2. Grinberg, M. (2018). Flask Web Development: Developing
Web Applications with Python. O'Reilly Media.
3. Pedregosa, F., et al. (2011). Scikit-learn: Machine learning in
Python. Journal of Machine Learning Research, 12, 2825-
2830.
4. OpenCV: Open-Source Computer Vision Library. (n.d.).
Retrieved from https://opencv.org/
5. Flask Documentation. (n.d.). Retrieved from
https://flask.palletsprojects.com/en/2.0.x/
6. Pandas Documentation. (n.d.). Retrieved from
https://pandas.pydata.org/docs/
7. Python Documentation. (n.d.). Retrieved from
https://docs.python.org/3/
8. Haarcascades for Face Detection. (n.d.). Retrieved from
https://github.com/opencv/opencv/tree/master/data/haarcascad
es