lokesh341 commited on
Commit
27d8552
·
1 Parent(s): fd3b717

Update services/overlay_service.py

Browse files
Files changed (1) hide show
  1. services/overlay_service.py +17 -8
services/overlay_service.py CHANGED
@@ -1,22 +1,31 @@
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
 
 
1
  import cv2
2
 
3
+ def overlay_boxes(frame, detected_items):
4
  """
5
  Add overlays (bounding boxes and labels) to a frame.
6
  Args:
7
  frame: Input frame (numpy array)
8
+ detected_items: List of detection dictionaries
9
  Returns:
10
  numpy array: Frame with overlays
11
  """
12
+ for item in detected_items:
13
+ if "coordinates" not in item or "label" not in item:
14
  continue
15
+ x_min, y_min, x_max, y_max = item["coordinates"]
16
+ label = item["label"]
17
+ # Choose color based on type
18
+ if item["type"] == "crack":
19
+ color = (255, 0, 0) # Red for cracks
20
+ elif item["type"] == "pothole":
21
+ color = (255, 165, 0) # Orange for potholes
22
+ else:
23
+ color = (0, 255, 0) # Green for other objects
24
+
25
  cv2.rectangle(frame, (x_min, y_min), (x_max, y_max), color, 2)
26
+ # Add severity if present
27
+ if "severity" in item:
28
+ label += f" - Severity: {item['severity'].capitalize()}"
29
  cv2.putText(frame, label, (x_min, y_min - 10),
30
  cv2.FONT_HERSHEY_SIMPLEX, 0.5, color, 2)
31
  return frame