Spaces:
Sleeping
Sleeping
dinhminh20521597
commited on
Commit
•
cffdeac
1
Parent(s):
aa82120
Update app.py
Browse files
app.py
CHANGED
@@ -12,15 +12,8 @@ import datetime
|
|
12 |
|
13 |
def IoU(bbox1, bbox2):
|
14 |
|
15 |
-
x1_left = bbox1[0]
|
16 |
-
|
17 |
-
x1_right = bbox1[2]
|
18 |
-
y1_bot = bbox1[3]
|
19 |
-
|
20 |
-
x2_left = bbox2[0]
|
21 |
-
y2_top = bbox2[1]
|
22 |
-
x2_right = bbox2[2]
|
23 |
-
y2_bot = bbox2[3]
|
24 |
|
25 |
x_left = max(x1_left, x2_left)
|
26 |
x_right = min(x1_right, x2_right)
|
@@ -91,30 +84,18 @@ def detect(inputimg, model):
|
|
91 |
|
92 |
time_mcs = time.microseconds
|
93 |
|
94 |
-
total_people = 0
|
95 |
-
|
96 |
-
withmask = 0
|
97 |
-
withoutmask = 0
|
98 |
-
|
99 |
list_objects = []
|
100 |
isRemove = []
|
101 |
-
for i in result[1]:
|
102 |
-
temp = i
|
103 |
-
temp = np.append(temp, 1)
|
104 |
-
list_objects.append(temp)
|
105 |
-
isRemove.append(0)
|
106 |
|
107 |
-
for
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
112 |
|
113 |
-
for i in result[3]:
|
114 |
-
temp = i
|
115 |
-
temp = np.append(temp, 3)
|
116 |
-
list_objects.append(temp)
|
117 |
-
isRemove.append(0)
|
118 |
|
119 |
for i in range(len(list_objects) - 1):
|
120 |
for j in range(i + 1, len(list_objects)):
|
@@ -127,7 +108,6 @@ def detect(inputimg, model):
|
|
127 |
isRemove[i] = 1
|
128 |
# print("IoU", abs(IoU(bbox1, bbox2)))
|
129 |
|
130 |
-
|
131 |
if list_objects[i][4] < 0.4:
|
132 |
isRemove[i] = 1
|
133 |
if list_objects[j][4] < 0.4:
|
@@ -161,25 +141,17 @@ def detect(inputimg, model):
|
|
161 |
color = (0, 0, 255)
|
162 |
text = "Without mask"
|
163 |
text += ": " + str(round(i[4], 2))
|
164 |
-
x1 = i[0]
|
165 |
-
|
166 |
-
x2 = i[2] - 1
|
167 |
-
y2 = i[3] - 1
|
168 |
|
169 |
-
x1 = round(x1)
|
170 |
-
y1 = round(y1)
|
171 |
-
x2 = round(x2)
|
172 |
-
y2 = round(y2)
|
173 |
|
174 |
img = cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
|
175 |
img = cv2.putText(img, text, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2)
|
176 |
output ="result_demo.jpg"
|
177 |
return img, total_people, incorrect, withmask, withoutmask, time_mcs/1000
|
178 |
|
179 |
-
st.title("
|
180 |
-
|
181 |
-
st.write("Lại Chí Thiện - 20520309")
|
182 |
-
st.write("Lê Thị Phương Vy - 20520355")
|
183 |
|
184 |
file_page, webcam_page, phonecam_page = st.tabs(["File", "Webcam", "Phone's camera"])
|
185 |
|
|
|
12 |
|
13 |
def IoU(bbox1, bbox2):
|
14 |
|
15 |
+
x1_left, y1_top, x1_right, y1_bot = bbox1[0], bbox1[1], bbox1[2], bbox1[3]
|
16 |
+
x2_left, y2_top, x2_right, y2_bot = bbox2[0], bbox2[1], bbox2[2], bbox2[3]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
|
18 |
x_left = max(x1_left, x2_left)
|
19 |
x_right = min(x1_right, x2_right)
|
|
|
84 |
|
85 |
time_mcs = time.microseconds
|
86 |
|
87 |
+
total_people, incorrect, withmask,withoutmask = 0, 0, 0, 0
|
88 |
+
|
|
|
|
|
|
|
89 |
list_objects = []
|
90 |
isRemove = []
|
|
|
|
|
|
|
|
|
|
|
91 |
|
92 |
+
for k in [1,2,3]:
|
93 |
+
for i in result[k]:
|
94 |
+
temp = i
|
95 |
+
temp = np.append(temp, k)
|
96 |
+
list_objects.append(temp)
|
97 |
+
isRemove.append(0)
|
98 |
|
|
|
|
|
|
|
|
|
|
|
99 |
|
100 |
for i in range(len(list_objects) - 1):
|
101 |
for j in range(i + 1, len(list_objects)):
|
|
|
108 |
isRemove[i] = 1
|
109 |
# print("IoU", abs(IoU(bbox1, bbox2)))
|
110 |
|
|
|
111 |
if list_objects[i][4] < 0.4:
|
112 |
isRemove[i] = 1
|
113 |
if list_objects[j][4] < 0.4:
|
|
|
141 |
color = (0, 0, 255)
|
142 |
text = "Without mask"
|
143 |
text += ": " + str(round(i[4], 2))
|
144 |
+
x1, y1 = i[0], i[1]
|
145 |
+
x2, y2 = i[2] - 1, i[3] - 1
|
|
|
|
|
146 |
|
147 |
+
x1, y1, x2, y2 = round(x1), round(y1), round(x2), round(y2)
|
|
|
|
|
|
|
148 |
|
149 |
img = cv2.rectangle(img, (x1, y1), (x2, y2), color, 3)
|
150 |
img = cv2.putText(img, text, (x1, y1-10), cv2.FONT_HERSHEY_SIMPLEX, 0.7, color, 2)
|
151 |
output ="result_demo.jpg"
|
152 |
return img, total_people, incorrect, withmask, withoutmask, time_mcs/1000
|
153 |
|
154 |
+
st.title("Face Mask Detection App")
|
|
|
|
|
|
|
155 |
|
156 |
file_page, webcam_page, phonecam_page = st.tabs(["File", "Webcam", "Phone's camera"])
|
157 |
|