lokesh341 commited on
Commit
d761fce
·
1 Parent(s): 6b73ec3

Update services/overlay_service.py

Browse files
Files changed (1) hide show
  1. services/overlay_service.py +18 -12
services/overlay_service.py CHANGED
@@ -1,16 +1,22 @@
 
1
  import cv2
2
 
3
- def overlay_boxes(frame, items):
4
- for item in items:
5
- box = item['box']
6
- x_min, y_min, x_max, y_max = map(int, box)
7
- severity = item['severity']
8
- if item['type'] == 'crack':
9
- color = (0, 0, 255) if severity == 'Severe' else (0, 255, 255) if severity == 'Moderate' else (0, 255, 0) if severity == 'Minor' else (255, 165, 0) # Orange for Underlying
10
- label = f"Crack: {severity}"
11
- else: # Hole
12
- color = (255, 0, 0) if severity == 'Severe' else (255, 255, 0) if severity == 'Moderate' else (0, 128, 0)
13
- label = f"Hole: {severity}"
 
 
 
 
14
  cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 2)
15
- cv2.putText(frame, label, (x_min, y_min - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
 
16
  return frame
 
1
+ # services/overlay_service.py
2
  import cv2
3
 
4
+ def add_overlay(frame, detections):
5
+ """
6
+ Add overlays (bounding boxes and labels) to a frame.
7
+ Args:
8
+ frame: Input frame (numpy array)
9
+ detections: List of detection dictionaries
10
+ Returns:
11
+ numpy array: Frame with overlays
12
+ """
13
+ for detection in detections:
14
+ if "coordinates" not in detection or "label" not in detection:
15
+ continue
16
+ x_min, y_min, x_max, y_max = detection["coordinates"]
17
+ label = detection["label"]
18
+ color = (0, 255, 0) # Green for generic overlays
19
  cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 2)
20
+ cv2.putText(frame, label, (x_min, y_min - 10),
21
+ cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
22
  return frame