dschandra commited on
Commit
d42c2d6
·
verified ·
1 Parent(s): ca78304

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +3 -2
utils.py CHANGED
@@ -2,9 +2,10 @@ import cv2
2
  import numpy as np
3
 
4
  def draw_boxes(frame, detections, class_names):
 
5
  for x1, y1, x2, y2, conf, cls_id in detections:
6
  label = class_names[int(cls_id)]
7
- color = (0, 255, 0) if label == 'ball' else (255, 0, 0)
8
  cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
9
  cv2.putText(frame, f"{label} {conf:.2f}", (int(x1), int(y1) - 5),
10
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
@@ -16,6 +17,6 @@ def overlay_decision_text(frame, decision):
16
  text = f"Decision: {decision}"
17
  text_size = cv2.getTextSize(text, font, 1.0, 2)[0]
18
  text_x = (frame.shape[1] - text_size[0]) // 2 # Center horizontally
19
- text_y = 50 # Near the top
20
  cv2.putText(frame, text, (text_x, text_y), font, 1.0, (0, 255, 255), 2, cv2.LINE_AA)
21
  return frame
 
2
  import numpy as np
3
 
4
  def draw_boxes(frame, detections, class_names):
5
+ """Draw bounding boxes and labels for detected objects (e.g., ball, player)."""
6
  for x1, y1, x2, y2, conf, cls_id in detections:
7
  label = class_names[int(cls_id)]
8
+ color = (0, 255, 0) if label == 'ball' else (255, 0, 0) # Green for ball, red for others
9
  cv2.rectangle(frame, (int(x1), int(y1)), (int(x2), int(y2)), color, 2)
10
  cv2.putText(frame, f"{label} {conf:.2f}", (int(x1), int(y1) - 5),
11
  cv2.FONT_HERSHEY_SIMPLEX, 0.6, color, 2)
 
17
  text = f"Decision: {decision}"
18
  text_size = cv2.getTextSize(text, font, 1.0, 2)[0]
19
  text_x = (frame.shape[1] - text_size[0]) // 2 # Center horizontally
20
+ text_y = 50 # Near top
21
  cv2.putText(frame, text, (text_x, text_y), font, 1.0, (0, 255, 255), 2, cv2.LINE_AA)
22
  return frame