Spaces:
Sleeping
Sleeping
Commit
·
a80b4b0
1
Parent(s):
04bc67a
Update app.py
Browse files
app.py
CHANGED
@@ -14,16 +14,26 @@ def detect_objects_on_image(image_path):
|
|
14 |
results = model.predict(image_path)
|
15 |
result = results[0]
|
16 |
output = []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
17 |
for box in result.boxes:
|
18 |
-
x1, y1, x2, y2 = [
|
19 |
-
round(x) for x in box.xyxy[0].tolist()
|
20 |
-
|
21 |
-
]
|
22 |
class_id = box.cls[0].item()
|
23 |
prob = round(box.conf[0].item(), 2)
|
|
|
|
|
|
|
24 |
output.append([
|
25 |
-
x1, y1, x2, y2,
|
26 |
])
|
|
|
27 |
cv2.rectangle(
|
28 |
image,
|
29 |
(x1, y1),
|
@@ -32,8 +42,9 @@ def detect_objects_on_image(image_path):
|
|
32 |
thickness=2,
|
33 |
lineType=cv2.LINE_AA
|
34 |
)
|
35 |
-
|
36 |
-
cv2.putText(image,
|
|
|
37 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
38 |
|
39 |
|
|
|
14 |
results = model.predict(image_path)
|
15 |
result = results[0]
|
16 |
output = []
|
17 |
+
|
18 |
+
class_names_mapping = {
|
19 |
+
"DPHF": "Double Person Helmet",
|
20 |
+
"DPNH": "Double Person No Helmet",
|
21 |
+
"SPHF": "Single Person Helmet",
|
22 |
+
"SPNH": "Single Person No Helmet",
|
23 |
+
"NP": "Number Plate"
|
24 |
+
}
|
25 |
+
|
26 |
for box in result.boxes:
|
27 |
+
x1, y1, x2, y2 = [round(x) for x in box.xyxy[0].tolist()]
|
|
|
|
|
|
|
28 |
class_id = box.cls[0].item()
|
29 |
prob = round(box.conf[0].item(), 2)
|
30 |
+
|
31 |
+
class_name = class_names_mapping.get(result.names[class_id], result.names[class_id])
|
32 |
+
|
33 |
output.append([
|
34 |
+
x1, y1, x2, y2, class_name, prob
|
35 |
])
|
36 |
+
|
37 |
cv2.rectangle(
|
38 |
image,
|
39 |
(x1, y1),
|
|
|
42 |
thickness=2,
|
43 |
lineType=cv2.LINE_AA
|
44 |
)
|
45 |
+
|
46 |
+
cv2.putText(image, class_name, (x1, y1), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (36, 255, 12), 2)
|
47 |
+
|
48 |
return cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
|
49 |
|
50 |
|