Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
@@ -27,7 +27,7 @@ for cls in myList:
|
|
27 |
encodeListknown = [face_recognition.face_encodings(img)[0] for img in Images]
|
28 |
|
29 |
# camera to take photo of user in question
|
30 |
-
file_name = st.
|
31 |
|
32 |
def add_attendance(name):
|
33 |
username = name
|
@@ -65,7 +65,7 @@ if file_name is not None:
|
|
65 |
|
66 |
# Initialize name as Unknown
|
67 |
name = "Unknown"
|
68 |
-
|
69 |
# Check if there's a match with known faces
|
70 |
if True in matches:
|
71 |
matchIndex = np.argmin(faceDis)
|
@@ -73,27 +73,27 @@ if file_name is not None:
|
|
73 |
|
74 |
# Append recognized name to the list
|
75 |
recognized_names.append(name)
|
76 |
-
|
77 |
-
# Draw rectangle
|
78 |
y1, x2, y2, x1 = faceLoc
|
79 |
y1, x2, y2, x1 = (y1 * 4), (x2 * 4), (y2 * 4) ,(x1 * 4)
|
80 |
|
81 |
-
#
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
cv2.rectangle(
|
86 |
-
cv2.putText(
|
87 |
-
|
88 |
# Update the database
|
89 |
add_attendance(name)
|
90 |
-
|
91 |
-
# Display the image with recognized names
|
92 |
-
st.image(
|
93 |
-
|
94 |
# Display recognized names
|
95 |
st.write("Recognized Names:")
|
96 |
for i, name in enumerate(recognized_names):
|
97 |
st.write(f"Face {i+1}: {name}")
|
98 |
else:
|
99 |
-
st.warning("No faces detected in the image. Face recognition failed.")
|
|
|
27 |
encodeListknown = [face_recognition.face_encodings(img)[0] for img in Images]
|
28 |
|
29 |
# camera to take photo of user in question
|
30 |
+
file_name = st.file_uploader("Upload image")
|
31 |
|
32 |
def add_attendance(name):
|
33 |
username = name
|
|
|
65 |
|
66 |
# Initialize name as Unknown
|
67 |
name = "Unknown"
|
68 |
+
|
69 |
# Check if there's a match with known faces
|
70 |
if True in matches:
|
71 |
matchIndex = np.argmin(faceDis)
|
|
|
73 |
|
74 |
# Append recognized name to the list
|
75 |
recognized_names.append(name)
|
76 |
+
|
77 |
+
# Draw rectangle and label on the image
|
78 |
y1, x2, y2, x1 = faceLoc
|
79 |
y1, x2, y2, x1 = (y1 * 4), (x2 * 4), (y2 * 4) ,(x1 * 4)
|
80 |
|
81 |
+
# Make a copy of the image array before drawing on it
|
82 |
+
image_copy = image.copy()
|
83 |
+
|
84 |
+
cv2.rectangle(image_copy, (x1, y1), (x2, y2), (0, 255, 0), 2)
|
85 |
+
cv2.rectangle(image_copy, (x1, y2 - 35), (x2, y2), (0, 255, 0), cv2.FILLED)
|
86 |
+
cv2.putText(image_copy, name, (x1 + 6, y2 - 6), cv2.FONT_HERSHEY_COMPLEX, 1, (255, 255, 255), 2)
|
87 |
+
|
88 |
# Update the database
|
89 |
add_attendance(name)
|
90 |
+
|
91 |
+
# Display the image with recognized names
|
92 |
+
st.image(image_copy, use_column_width=True, output_format="PNG")
|
93 |
+
|
94 |
# Display recognized names
|
95 |
st.write("Recognized Names:")
|
96 |
for i, name in enumerate(recognized_names):
|
97 |
st.write(f"Face {i+1}: {name}")
|
98 |
else:
|
99 |
+
st.warning("No faces detected in the image. Face recognition failed.")
|