0% found this document useful (0 votes)
10 views2 pages

Real-Time Face Recognition Attendance System

This document outlines a Python script that utilizes OpenCV and scikit-learn to implement a facial recognition attendance system. It captures video from a webcam, detects faces, and uses a KNeighborsClassifier to identify individuals, logging their attendance in a CSV file. The script also includes voice feedback for attendance confirmation and manages attendance records based on the date.

Uploaded by

nikhil.goo20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views2 pages

Real-Time Face Recognition Attendance System

This document outlines a Python script that utilizes OpenCV and scikit-learn to implement a facial recognition attendance system. It captures video from a webcam, detects faces, and uses a KNeighborsClassifier to identify individuals, logging their attendance in a CSV file. The script also includes voice feedback for attendance confirmation and manages attendance records based on the date.

Uploaded by

nikhil.goo20
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

from sklearn.

neighbors import KNeighborsClassifier


import cv2
import pickle
import numpy as np
import os
import csv
import time
from datetime import datetime

from [Link] import Dispatch

def speak(str1):
speak=Dispatch(("[Link]"))
[Link](str1)

video=[Link](0)
facedetect=[Link]('data/haarcascade_frontalface_default.xml')

with open('data/[Link]', 'rb') as w:


LABELS=[Link](w)
with open('data/faces_data.pkl', 'rb') as f:
FACES=[Link](f)

print('Shape of Faces matrix --> ', [Link])

knn=KNeighborsClassifier(n_neighbors=5)
[Link](FACES, LABELS)

imgBackground=[Link]("[Link]")

COL_NAMES = ['NAME', 'TIME']

while True:
ret,frame=[Link]()
gray=[Link](frame, cv2.COLOR_BGR2GRAY)
faces=[Link](gray, 1.3 ,5)
for (x,y,w,h) in faces:
crop_img=frame[y:y+h, x:x+w, :]
resized_img=[Link](crop_img, (50,50)).flatten().reshape(1,-1)
output=[Link](resized_img)
ts=[Link]()
date=[Link](ts).strftime("%d-%m-%Y")
timestamp=[Link](ts).strftime("%H:%M-%S")
exist=[Link]("Attendance/Attendance_" + date + ".csv")
[Link](frame, (x,y), (x+w, y+h), (0,0,255), 1)
[Link](frame,(x,y),(x+w,y+h),(50,50,255),2)
[Link](frame,(x,y-40),(x+w,y),(50,50,255),-1)
[Link](frame, str(output[0]), (x,y-15), cv2.FONT_HERSHEY_COMPLEX, 1,
(255,255,255), 1)
[Link](frame, (x,y), (x+w, y+h), (50,50,255), 1)
attendance=[str(output[0]), str(timestamp)]
imgBackground[162:162 + 480, 55:55 + 640] = frame
[Link]("Frame",imgBackground)
k=[Link](1)
if k==ord('o'):
speak("Attendance Taken..")
[Link](5)
if exist:
with open("Attendance/Attendance_" + date + ".csv", "+a") as csvfile:
writer=[Link](csvfile)
[Link](attendance)
[Link]()
else:
with open("Attendance/Attendance_" + date + ".csv", "+a") as csvfile:
writer=[Link](csvfile)
[Link](COL_NAMES)
[Link](attendance)
[Link]()
if k==ord('q'):
break
[Link]()
[Link]()

You might also like