dschandra commited on
Commit
d89395a
·
verified ·
1 Parent(s): 18d35d6

Update utils.py

Browse files
Files changed (1) hide show
  1. utils.py +3 -5
utils.py CHANGED
@@ -2,21 +2,19 @@ import cv2
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)
12
  return frame
13
 
14
  def overlay_decision_text(frame, decision):
15
- """Overlay LBW decision text (e.g., 'Out' or 'Not Out') on the frame."""
16
  font = cv2.FONT_HERSHEY_SIMPLEX
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
 
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)
11
  return frame
12
 
13
  def overlay_decision_text(frame, decision):
 
14
  font = cv2.FONT_HERSHEY_SIMPLEX
15
  text = f"Decision: {decision}"
16
  text_size = cv2.getTextSize(text, font, 1.0, 2)[0]
17
+ text_x = (frame.shape[1] - text_size[0]) // 2
18
+ text_y = 50
19
  cv2.putText(frame, text, (text_x, text_y), font, 1.0, (0, 255, 255), 2, cv2.LINE_AA)
20
  return frame