SuriRaja commited on
Commit
f2da774
·
1 Parent(s): 62ae84e

Update services/overlay_service.py

Browse files
Files changed (1) hide show
  1. services/overlay_service.py +13 -7
services/overlay_service.py CHANGED
@@ -1,10 +1,16 @@
1
  import cv2
2
 
3
- def overlay_boxes(image, boxes):
4
- # Directly use the image (NumPy array)
5
  for box in boxes:
6
- x, y, w, h = box
7
- x1, y1, x2, y2 = int(x), int(y), int(x + w), int(y + h)
8
- cv2.rectangle(image, (x1, y1), (x2, y2), (0, 255, 0), 2)
9
- cv2.putText(image, 'Anomaly', (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.6, (0, 255, 0), 2)
10
- return image
 
 
 
 
 
 
 
 
1
  import cv2
2
 
3
+ def overlay_boxes(frame, boxes):
 
4
  for box in boxes:
5
+ x1, y1, x2, y2 = map(int, box['box'])
6
+ label = box.get('label', 'Anomaly')
7
+ confidence = box.get('score', 0)
8
+
9
+ # Draw box
10
+ cv2.rectangle(frame, (x1, y1), (x2, y2), (0, 255, 0), 2)
11
+
12
+ # Draw label
13
+ text = f"{label} ({confidence:.2f})"
14
+ cv2.putText(frame, text, (x1, max(y1 - 10, 0)), cv2.FONT_HERSHEY_SIMPLEX,
15
+ 0.5, (255, 0, 0), 2)
16
+ return frame