Spaces:
Runtime error
Runtime error
File size: 2,520 Bytes
22e0d2f 3657998 17aa4ec 3657998 17aa4ec 3657998 17aa4ec 3657998 17aa4ec 3657998 17aa4ec 3657998 17aa4ec 3657998 17aa4ec 3657998 17aa4ec 3657998 17aa4ec 3657998 a104a54 17aa4ec 3657998 17aa4ec a104a54 3657998 17aa4ec 3657998 17aa4ec a104a54 3657998 17aa4ec a104a54 17aa4ec |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 |
import face_recognition
import cv2
import numpy as np
import csv
from datetime import datetime
video_capture = cv2.VideoCapture(0)
sir_image = face_recognition.load_image_file("photos/sir.jpeg")
sir_encoding = face_recognition.face_encodings(sir_image)[0]
vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
known_face_encoding = [sir_encoding, vikas_encoding]
known_faces_names = ["Sarwan Sir", "Vikas"]
students = known_faces_names.copy()
face_locations = []
face_encodings = []
face_names = []
s = True
now = datetime.now()
current_date = now.strftime("%Y-%m-%d")
f = open(current_date + '.csv', 'w+', newline='')
lnwriter = csv.writer(f)
############################
import io
import streamlit as st
bytes_data = None
img_file_buffer = st.camera_input("Take a picture")
if img_file_buffer is not None:
while True:
_, frame = video_capture.read()
if frame is not None and frame.size > 0:
small_frame = cv2.resize(frame, (0, 0), fx=0.25, fy=0.25)
rgb_small_frame = small_frame[:, :, ::-1]
if s:
face_locations = face_recognition.face_locations(rgb_small_frame)
face_encodings = face_recognition.face_encodings(small_frame, face_locations)
face_names = []
for face_encoding in face_encodings:
matches = face_recognition.compare_faces(known_face_encoding, face_encoding)
name = ""
face_distance = face_recognition.face_distance(known_face_encoding, face_encoding)
best_match_index = np.argmin(face_distance)
if matches[best_match_index]:
name = known_faces_names[best_match_index]
face_names.append(name)
if name in known_faces_names:
if name in students:
students.remove(name)
print(students)
current_time = now.strftime("%H-%M-%S")
lnwriter.writerow([name, current_time, "Present"])
cv2.imshow("attendance system", frame)
else:
print("Failed to retrieve frame from video capture.")
break
if cv2.waitKey(1) & 0xFF == ord('q'):
break
video_capture.release()
cv2.destroyAllWindows()
f.close()
if bytes_data is None:
st.stop() |