Spaces:
Runtime error
Runtime error
Shafeek Saleem
commited on
Commit
•
caa436d
1
Parent(s):
19127c5
face recog fixed
Browse files- pages/4_Face Recognition.py +48 -57
pages/4_Face Recognition.py
CHANGED
@@ -7,6 +7,7 @@ import time
|
|
7 |
import face_recognition
|
8 |
import cv2
|
9 |
import numpy as np
|
|
|
10 |
|
11 |
initialize_login()
|
12 |
initialize_level()
|
@@ -14,18 +15,6 @@ initialize_level()
|
|
14 |
LEVEL = 4
|
15 |
|
16 |
|
17 |
-
def infer(image):
|
18 |
-
time.sleep(1)
|
19 |
-
output = query(image)
|
20 |
-
cols = st.columns(2)
|
21 |
-
cols[0].image(image, use_column_width=True)
|
22 |
-
with cols[1]:
|
23 |
-
for item in output:
|
24 |
-
st.progress(item["score"], text=item["label"])
|
25 |
-
|
26 |
-
# Get a reference to webcam #0 (the default one)
|
27 |
-
video_capture = cv2.VideoCapture(0)
|
28 |
-
|
29 |
def step4_page():
|
30 |
st.header("Face Recognition: Trying It Out")
|
31 |
st.write(
|
@@ -50,51 +39,53 @@ def step4_page():
|
|
50 |
known_face_encodings.append(known_face_encoding)
|
51 |
known_face_names.append(face_name)
|
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 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
#
|
96 |
-
|
97 |
-
|
|
|
|
|
98 |
|
99 |
st.info("Click on the button below to complete this level!")
|
100 |
if st.button("Complete Level"):
|
|
|
7 |
import face_recognition
|
8 |
import cv2
|
9 |
import numpy as np
|
10 |
+
from PIL import Image
|
11 |
|
12 |
initialize_login()
|
13 |
initialize_level()
|
|
|
15 |
LEVEL = 4
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
def step4_page():
|
19 |
st.header("Face Recognition: Trying It Out")
|
20 |
st.write(
|
|
|
39 |
known_face_encodings.append(known_face_encoding)
|
40 |
known_face_names.append(face_name)
|
41 |
|
42 |
+
st.info("Select an image to analyze!")
|
43 |
+
input_type = st.radio("Select the Input Type", ["Image", "Camera"])
|
44 |
+
|
45 |
+
if input_type == "Camera":
|
46 |
+
picture = st.camera_input("Take a picture")
|
47 |
+
else:
|
48 |
+
picture = st.file_uploader("Upload an image", type=["png", "jpg", "jpeg"])
|
49 |
+
if picture:
|
50 |
+
image = face_recognition.load_image_file(picture)
|
51 |
+
face_locations = face_recognition.face_locations(image)
|
52 |
+
face_encodings = face_recognition.face_encodings(image, face_locations)
|
53 |
+
|
54 |
+
# Loop through each face in this image
|
55 |
+
cols = st.columns(len(face_encodings))
|
56 |
+
i = 0
|
57 |
+
for (top, right, bottom, left), face_encoding in zip(face_locations, face_encodings):
|
58 |
+
# See if the face is a match for the known face(s)
|
59 |
+
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
|
60 |
+
|
61 |
+
name = "Unknown"
|
62 |
+
# If a match was found in known_face_encodings, just use the first one.
|
63 |
+
if True in matches:
|
64 |
+
first_match_index = matches.index(True)
|
65 |
+
name = known_face_names[first_match_index]
|
66 |
+
|
67 |
+
face_image = image[top:bottom, left:right]
|
68 |
+
pil_image = Image.fromarray(face_image)
|
69 |
+
cols[i].image(pil_image, use_column_width=True)
|
70 |
+
cols[i].write("Person name: " +name)
|
71 |
+
i+=1
|
72 |
+
|
73 |
+
# # Draw a box around the face
|
74 |
+
# cv2.rectangle(frame, (left, top), (right, bottom), (0, 0, 255), 2)
|
75 |
+
#
|
76 |
+
# # Draw a label with a name below the face
|
77 |
+
# cv2.rectangle(frame, (left, bottom - 35), (right, bottom), (0, 0, 255), cv2.FILLED)
|
78 |
+
# font = cv2.FONT_HERSHEY_DUPLEX
|
79 |
+
# cv2.putText(frame, name, (left + 6, bottom - 6), font, 1.0, (255, 255, 255), 1)
|
80 |
+
#
|
81 |
+
# # Display the resulting image
|
82 |
+
# cv2.imshow('Video', frame)
|
83 |
+
# # Hit 'q' on the keyboard to quit!
|
84 |
+
# if cv2.waitKey(1) & 0xFF == ord('q'):
|
85 |
+
# break
|
86 |
+
# # Release handle to the webcam
|
87 |
+
# video_capture.release()
|
88 |
+
# cv2.destroyAllWindows()
|
89 |
|
90 |
st.info("Click on the button below to complete this level!")
|
91 |
if st.button("Complete Level"):
|