Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -50,80 +50,66 @@ def test_connect():
|
|
50 |
|
51 |
@socket.on("image")
|
52 |
def receive_image(image):
|
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 |
-
sir_encoding = face_recognition.face_encodings(sir_image)[0]
|
81 |
-
|
82 |
-
vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
|
83 |
-
vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
|
84 |
-
|
85 |
-
lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
|
86 |
-
lalit_encoding = face_recognition.face_encodings(lalit_image)[0]
|
87 |
-
|
88 |
-
jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
|
89 |
-
jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]
|
90 |
-
|
91 |
-
maam_image = face_recognition.load_image_file("photos/maam.png")
|
92 |
-
maam_encoding = face_recognition.face_encodings(maam_image)[0]
|
93 |
-
|
94 |
-
known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]
|
95 |
-
emit("result",{"name":"level1","score":"34"})
|
96 |
-
students = known_faces_names.copy()
|
97 |
-
|
98 |
-
face_locations = []
|
99 |
-
face_encodings = []
|
100 |
-
face_names = []
|
101 |
-
|
102 |
-
# now = datetime.now()
|
103 |
-
# current_date = now.strftime("%Y-%m-%d")
|
104 |
-
# csv_file = open(f"{current_date}.csv", "a+", newline="")
|
105 |
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
|
115 |
-
|
116 |
-
|
117 |
-
name
|
118 |
-
|
119 |
-
|
120 |
-
|
121 |
-
name =
|
122 |
-
|
123 |
-
|
|
|
|
|
124 |
|
125 |
-
|
126 |
-
|
|
|
|
|
|
|
|
|
127 |
|
128 |
|
129 |
# # for name in face_names:
|
|
|
50 |
|
51 |
@socket.on("image")
|
52 |
def receive_image(image):
|
53 |
+
s = True
|
54 |
+
while s :
|
55 |
+
|
56 |
+
# Decode the base64-encoded image data
|
57 |
+
image = base64_to_image(image)
|
58 |
+
|
59 |
+
known_faces_names = ["Sarwan Sir", "Vikas","Lalit","Jasmeen","Anita Ma'am"]
|
60 |
+
known_face_encodings = []
|
61 |
|
62 |
+
# Load known face encodings
|
63 |
+
sir_image = face_recognition.load_image_file("photos/sir.jpeg")
|
64 |
+
sir_encoding = face_recognition.face_encodings(sir_image)[0]
|
65 |
+
|
66 |
+
vikas_image = face_recognition.load_image_file("photos/vikas.jpg")
|
67 |
+
vikas_encoding = face_recognition.face_encodings(vikas_image)[0]
|
68 |
+
|
69 |
+
lalit_image = face_recognition.load_image_file("photos/lalit.jpg")
|
70 |
+
lalit_encoding = face_recognition.face_encodings(lalit_image)[0]
|
71 |
+
|
72 |
+
jasmine_image = face_recognition.load_image_file("photos/jasmine.jpg")
|
73 |
+
jasmine_encoding = face_recognition.face_encodings(jasmine_image)[0]
|
74 |
+
|
75 |
+
maam_image = face_recognition.load_image_file("photos/maam.png")
|
76 |
+
maam_encoding = face_recognition.face_encodings(maam_image)[0]
|
77 |
+
|
78 |
+
known_face_encodings = [sir_encoding, vikas_encoding,lalit_encoding,jasmine_encoding,maam_encoding]
|
79 |
+
emit("result",{"name":"level1","score":"34"})
|
80 |
+
students = known_faces_names.copy()
|
81 |
+
|
82 |
+
face_locations = []
|
83 |
+
face_encodings = []
|
84 |
+
face_names = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
85 |
|
86 |
+
# now = datetime.now()
|
87 |
+
# current_date = now.strftime("%Y-%m-%d")
|
88 |
+
# csv_file = open(f"{current_date}.csv", "a+", newline="")
|
89 |
+
|
90 |
+
# csv_writer = csv.writer(csv_file)
|
91 |
+
small_frame = cv2.resize(image, (0, 0), fx=0.25, fy=0.25)
|
92 |
+
rgb_small_frame = small_frame[:, :, ::-1]
|
93 |
+
emit("result",{"name":"level222","score":"34"})
|
94 |
+
face_locations = face_recognition.face_locations(rgb_small_frame)
|
95 |
+
face_encodings = face_recognition.face_encodings(small_frame, face_locations)
|
96 |
+
face_names = []
|
97 |
+
emit("result",{"name":"level 33","score":str(len(face_encodings))})
|
98 |
+
for face_encoding in face_encodings:
|
99 |
+
emit("result",{"name":"in for ","score":"34"})
|
100 |
+
matches = face_recognition.compare_faces(known_face_encodings, face_encoding)
|
101 |
+
name = ""
|
102 |
+
face_distance = face_recognition.face_distance(known_face_encodings, face_encoding)
|
103 |
+
best_match_index = np.argmin(face_distance)
|
104 |
+
if matches[best_match_index]:
|
105 |
+
name = known_faces_names[best_match_index]
|
106 |
|
107 |
+
face_names.append(name)
|
108 |
+
s = False
|
109 |
+
break
|
110 |
+
|
111 |
+
emit("result",{"name":str(name)+"------------","score":"myScore"})
|
112 |
+
|
113 |
|
114 |
|
115 |
# # for name in face_names:
|