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