Irpan commited on
Commit
443e9fb
1 Parent(s): 54c5004
player_ball_assigner/__init__.py ADDED
@@ -0,0 +1 @@
 
 
1
+ from .player_ball_assigner import PlayerBallAssigner
player_ball_assigner/player_ball_assigner.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import sys
2
+ sys.path.append('../')
3
+ from utils import get_center_of_bbox, measure_distance
4
+
5
+ class PlayerBallAssigner():
6
+ def __init__(self):
7
+ self.max_player_ball_distance = 70
8
+
9
+ def assign_ball_to_player(self,players,ball_bbox):
10
+ ball_position = get_center_of_bbox(ball_bbox)
11
+
12
+ miniumum_distance = 99999
13
+ assigned_player=-1
14
+
15
+ for player_id, player in players.items():
16
+ player_bbox = player['bbox']
17
+
18
+ distance_left = measure_distance((player_bbox[0],player_bbox[-1]),ball_position)
19
+ distance_right = measure_distance((player_bbox[2],player_bbox[-1]),ball_position)
20
+ distance = min(distance_left,distance_right)
21
+
22
+ if distance < self.max_player_ball_distance:
23
+ if distance < miniumum_distance:
24
+ miniumum_distance = distance
25
+ assigned_player = player_id
26
+
27
+ return assigned_player