Spaces:
Sleeping
Sleeping
Commit
·
7c3e7c7
1
Parent(s):
738a81e
Update app.py
Browse files
app.py
CHANGED
@@ -71,13 +71,13 @@ if img_file_buffer is not None:
|
|
71 |
|
72 |
img = np.asarray(image1)
|
73 |
img = cv2.resize(img,(0,0),None,0.25,0.25)
|
74 |
-
st.write("
|
75 |
|
76 |
#image gray
|
77 |
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
78 |
faces = face_cascade.detectMultiScale(
|
79 |
image=img_gray, scaleFactor=1.3, minNeighbors=5)
|
80 |
-
st.write("
|
81 |
for (x, y, w, h) in faces:
|
82 |
cv2.rectangle(img=img, pt1=(x, y), pt2=(
|
83 |
x + w, y + h), color=(255, 0, 0), thickness=2)
|
@@ -91,24 +91,24 @@ if img_file_buffer is not None:
|
|
91 |
maxindex = int(np.argmax(prediction))
|
92 |
finalout = emotion_dict[maxindex]
|
93 |
output = str(finalout)
|
94 |
-
st.write(
|
95 |
label_position = (x, y)
|
96 |
img = cv2.putText(img, output, label_position, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
|
97 |
st.image(img, use_column_width=True)
|
98 |
-
st.write("
|
99 |
|
100 |
#########################
|
101 |
imgS = cv2.resize(image,(0,0),None,0.25,0.25)
|
102 |
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
|
103 |
facesCurFrame = face_recognition.face_locations(imgS)
|
104 |
encodesCurFrame = face_recognition.face_encodings(imgS,facesCurFrame)
|
105 |
-
st.write("
|
106 |
for encodeFace,faceLoc in zip(encodesCurFrame,facesCurFrame):
|
107 |
matches = face_recognition.compare_faces(encodeListknown,encodeFace)
|
108 |
faceDis = face_recognition.face_distance(encodeListknown,encodeFace)
|
109 |
#print(faceDis)
|
110 |
matchIndex = np.argmin(faceDis)
|
111 |
-
st.write("
|
112 |
if matches[matchIndex]:
|
113 |
name = classnames[matchIndex]
|
114 |
st.write(name)
|
@@ -117,7 +117,7 @@ if img_file_buffer is not None:
|
|
117 |
cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),2)
|
118 |
cv2.rectangle(image,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
|
119 |
cv2.putText(image,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255, 255, 255),2)
|
120 |
-
st.write("
|
121 |
##############
|
122 |
if name:
|
123 |
if output=='happy':
|
|
|
71 |
|
72 |
img = np.asarray(image1)
|
73 |
img = cv2.resize(img,(0,0),None,0.25,0.25)
|
74 |
+
st.write("resize")
|
75 |
|
76 |
#image gray
|
77 |
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
|
78 |
faces = face_cascade.detectMultiScale(
|
79 |
image=img_gray, scaleFactor=1.3, minNeighbors=5)
|
80 |
+
st.write("gray")
|
81 |
for (x, y, w, h) in faces:
|
82 |
cv2.rectangle(img=img, pt1=(x, y), pt2=(
|
83 |
x + w, y + h), color=(255, 0, 0), thickness=2)
|
|
|
91 |
maxindex = int(np.argmax(prediction))
|
92 |
finalout = emotion_dict[maxindex]
|
93 |
output = str(finalout)
|
94 |
+
st.write(output)
|
95 |
label_position = (x, y)
|
96 |
img = cv2.putText(img, output, label_position, cv2.FONT_HERSHEY_SIMPLEX, 1, (0, 255, 0), 2)
|
97 |
st.image(img, use_column_width=True)
|
98 |
+
st.write("emotion done")
|
99 |
|
100 |
#########################
|
101 |
imgS = cv2.resize(image,(0,0),None,0.25,0.25)
|
102 |
imgS = cv2.cvtColor(imgS, cv2.COLOR_BGR2RGB)
|
103 |
facesCurFrame = face_recognition.face_locations(imgS)
|
104 |
encodesCurFrame = face_recognition.face_encodings(imgS,facesCurFrame)
|
105 |
+
st.write("recog")
|
106 |
for encodeFace,faceLoc in zip(encodesCurFrame,facesCurFrame):
|
107 |
matches = face_recognition.compare_faces(encodeListknown,encodeFace)
|
108 |
faceDis = face_recognition.face_distance(encodeListknown,encodeFace)
|
109 |
#print(faceDis)
|
110 |
matchIndex = np.argmin(faceDis)
|
111 |
+
st.write("matching")
|
112 |
if matches[matchIndex]:
|
113 |
name = classnames[matchIndex]
|
114 |
st.write(name)
|
|
|
117 |
cv2.rectangle(image,(x1,y1),(x2,y2),(0,255,0),2)
|
118 |
cv2.rectangle(image,(x1,y2-35),(x2,y2),(0,255,0),cv2.FILLED)
|
119 |
cv2.putText(image,name,(x1+6,y2-6),cv2.FONT_HERSHEY_COMPLEX,1,(255, 255, 255),2)
|
120 |
+
st.write("matched")
|
121 |
##############
|
122 |
if name:
|
123 |
if output=='happy':
|