Spaces:
Sleeping
Sleeping
Update utils.py
Browse files
utils.py
CHANGED
@@ -1,21 +1,21 @@
|
|
1 |
-
|
2 |
-
|
3 |
-
color = (0, 255, 0)
|
4 |
-
|
5 |
-
if has_impact and hit_stumps:
|
6 |
-
decision = "OUT"
|
7 |
-
color = (0, 0, 255)
|
8 |
-
|
9 |
-
cv2.putText(frame, f"LBW DECISION: {decision}", (50, 150), cv2.FONT_HERSHEY_SIMPLEX, 2, color, 5)
|
10 |
-
|
11 |
-
if has_impact:
|
12 |
-
cv2.putText(frame, "✔️ Impact Detected", (50, 250), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
|
13 |
-
else:
|
14 |
-
cv2.putText(frame, "❌ No Pad Impact", (50, 250), cv2.FONT_HERSHEY_SIMPLEX, 1, (100, 100, 100), 2)
|
15 |
-
|
16 |
-
if hit_stumps:
|
17 |
-
cv2.putText(frame, "✔️ Ball Would Hit Stumps", (50, 300), cv2.FONT_HERSHEY_SIMPLEX, 1, (255, 255, 255), 2)
|
18 |
-
else:
|
19 |
-
cv2.putText(frame, "❌ Ball Missed Stumps", (50, 300), cv2.FONT_HERSHEY_SIMPLEX, 1, (100, 100, 100), 2)
|
20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
return frame
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
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)
|
11 |
return frame
|
12 |
+
|
13 |
+
def overlay_decision_text(frame, decision):
|
14 |
+
"""Overlay LBW decision text (e.g., 'Out' or 'Not Out') on the frame."""
|
15 |
+
font = cv2.FONT_HERSHEY_SIMPLEX
|
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
|