AjaykumarPilla commited on
Commit
4574aff
·
verified ·
1 Parent(s): 0e33428

Update gully_drs_core/ball_detection.py

Browse files
Files changed (1) hide show
  1. gully_drs_core/ball_detection.py +22 -2
gully_drs_core/ball_detection.py CHANGED
@@ -3,6 +3,12 @@ import cv2
3
  import numpy as np
4
  from .model_utils import load_model
5
 
 
 
 
 
 
 
6
  def analyze_video(file_path):
7
  model = load_model()
8
  cap = cv2.VideoCapture(file_path)
@@ -21,7 +27,7 @@ def analyze_video(file_path):
21
  for r in results:
22
  for box in r.boxes:
23
  cls = int(box.cls[0])
24
- if cls == 32: # Assuming class 32 = cricket ball
25
  x1, y1, x2, y2 = map(int, box.xyxy[0])
26
  cx, cy = (x1 + x2) // 2, (y1 + y2) // 2
27
  ball_path.append((cx, cy))
@@ -29,8 +35,22 @@ def analyze_video(file_path):
29
  frames.append(frame)
30
 
31
  cap.release()
 
 
 
 
 
 
 
 
 
 
32
  return {
33
  "trajectory": ball_path,
34
  "fps": fps,
35
- "frames": frames
 
 
 
 
36
  }
 
3
  import numpy as np
4
  from .model_utils import load_model
5
 
6
+ def find_bounce_point(path):
7
+ for i in range(1, len(path)-1):
8
+ if path[i-1][1] > path[i][1] < path[i+1][1]: # y dips = bounce
9
+ return path[i]
10
+ return None
11
+
12
  def analyze_video(file_path):
13
  model = load_model()
14
  cap = cv2.VideoCapture(file_path)
 
27
  for r in results:
28
  for box in r.boxes:
29
  cls = int(box.cls[0])
30
+ if cls == 32: # cricket ball
31
  x1, y1, x2, y2 = map(int, box.xyxy[0])
32
  cx, cy = (x1 + x2) // 2, (y1 + y2) // 2
33
  ball_path.append((cx, cy))
 
35
  frames.append(frame)
36
 
37
  cap.release()
38
+
39
+ bounce_point = find_bounce_point(ball_path)
40
+ impact_point = ball_path[-1] if ball_path else None
41
+
42
+ # Define stump zone (middle 1/3 width, bottom 100px)
43
+ stump_zone = (width // 2 - 30, height - 100, width // 2 + 30, height)
44
+
45
+ # Decision: is the last point in the stump zone?
46
+ decision = "OUT" if impact_point and stump_zone[0] <= impact_point[0] <= stump_zone[2] else "NOT OUT"
47
+
48
  return {
49
  "trajectory": ball_path,
50
  "fps": fps,
51
+ "frames": frames,
52
+ "bounce_point": bounce_point,
53
+ "impact_point": impact_point,
54
+ "decision": decision,
55
+ "stump_zone": stump_zone
56
  }