Spaces:
Runtime error
Runtime error
Create overlay_service.py
Browse files- services/overlay_service.py +21 -0
services/overlay_service.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import cv2
|
2 |
+
|
3 |
+
def overlay_boxes(image_path, boxes):
|
4 |
+
image = cv2.imread(image_path)
|
5 |
+
if image is None:
|
6 |
+
return None
|
7 |
+
|
8 |
+
for box in boxes:
|
9 |
+
x1, y1, x2, y2, label = box
|
10 |
+
color = (0, 255, 0) if label == "normal" else (0, 0, 255)
|
11 |
+
cv2.rectangle(image, (x1, y1), (x2, y2), color, 2)
|
12 |
+
cv2.putText(
|
13 |
+
image,
|
14 |
+
label,
|
15 |
+
(x1, y1 - 10),
|
16 |
+
cv2.FONT_HERSHEY_SIMPLEX,
|
17 |
+
0.5,
|
18 |
+
color,
|
19 |
+
2
|
20 |
+
)
|
21 |
+
return image
|