openstarlab-spaceEval 0.0.1__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- openstarlab_spaceeval-0.0.1/LICENSE.md +23 -0
- openstarlab_spaceeval-0.0.1/PKG-INFO +41 -0
- openstarlab_spaceeval-0.0.1/README.md +21 -0
- openstarlab_spaceeval-0.0.1/openstarlab_spaceEval.egg-info/PKG-INFO +41 -0
- openstarlab_spaceeval-0.0.1/openstarlab_spaceEval.egg-info/SOURCES.txt +23 -0
- openstarlab_spaceeval-0.0.1/openstarlab_spaceEval.egg-info/dependency_links.txt +1 -0
- openstarlab_spaceeval-0.0.1/openstarlab_spaceEval.egg-info/requires.txt +6 -0
- openstarlab_spaceeval-0.0.1/openstarlab_spaceEval.egg-info/top_level.txt +2 -0
- openstarlab_spaceeval-0.0.1/pyproject.toml +39 -0
- openstarlab_spaceeval-0.0.1/setup.cfg +4 -0
- openstarlab_spaceeval-0.0.1/spaceeval/__init__.py +4 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/__init__.py +0 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/__init__.py +0 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/application/__init__.py +0 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/application/heatmap.py +334 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/main_class_basketball/__init__.py +0 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/main_class_basketball/main.py +40 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/model_parameter/__init__.py +0 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/models/BIMOS.py +374 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/models/BMOS.py +353 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/models/__init__.py +0 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/utils/SportVU_IO.py +85 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/utils/__init__.py +0 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/basketball/utils/get_residual_param.py +115 -0
- openstarlab_spaceeval-0.0.1/spaceeval/sports/main_class.py +36 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2021 Friends-of-Tracking-Data-FoTD
|
|
4
|
+
Copyright (c) 2022 Masakiyo Teranishi and Keisuke Fujii
|
|
5
|
+
Copyright (c) 2025 Titouan Jeannot, Keisuke Fujii, OpenSTARLab
|
|
6
|
+
|
|
7
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
8
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
9
|
+
in the Software without restriction, including without limitation the rights
|
|
10
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
11
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
12
|
+
furnished to do so, subject to the following conditions:
|
|
13
|
+
|
|
14
|
+
The above copyright notice and this permission notice shall be included in all
|
|
15
|
+
copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
18
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
19
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
20
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
21
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
22
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
23
|
+
SOFTWARE.
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: openstarlab-spaceEval
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: openstarlab space eval package
|
|
5
|
+
Author-email: Calvin Yeung <yeung.chikwong@g.sp.m.is.nagoya-u.ac.jp>
|
|
6
|
+
License: Apache License 2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/open-starlab/
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE.md
|
|
14
|
+
Requires-Dist: pandas
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Requires-Dist: matplotlib
|
|
17
|
+
Requires-Dist: scipy
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Requires-Dist: opencv-python
|
|
20
|
+
|
|
21
|
+
# OpenSTARLab SpaceEval package
|
|
22
|
+
|
|
23
|
+
## Introduction
|
|
24
|
+
The OpenSTARLab SpaceEval package is designed to provide simple and efficient way to visualize and estimate space evaluation for different sports. This package supports the data preprocessed by the OpenSTARLab PreProcessing package.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
This package is continuously evolving to support future OpenSTARLab projects. If you have any suggestions or encounter any bugs, please feel free to open an issue.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
- To install this package via PyPI
|
|
33
|
+
```
|
|
34
|
+
pip install openstarlab-spaceEval
|
|
35
|
+
```
|
|
36
|
+
- To install manually
|
|
37
|
+
```
|
|
38
|
+
git clone git@github.com:open-starlab/spaceEval.git
|
|
39
|
+
cd ./spaceEval
|
|
40
|
+
pip install -e .
|
|
41
|
+
```
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# OpenSTARLab SpaceEval package
|
|
2
|
+
|
|
3
|
+
## Introduction
|
|
4
|
+
The OpenSTARLab SpaceEval package is designed to provide simple and efficient way to visualize and estimate space evaluation for different sports. This package supports the data preprocessed by the OpenSTARLab PreProcessing package.
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
This package is continuously evolving to support future OpenSTARLab projects. If you have any suggestions or encounter any bugs, please feel free to open an issue.
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
## Installation
|
|
11
|
+
|
|
12
|
+
- To install this package via PyPI
|
|
13
|
+
```
|
|
14
|
+
pip install openstarlab-spaceEval
|
|
15
|
+
```
|
|
16
|
+
- To install manually
|
|
17
|
+
```
|
|
18
|
+
git clone git@github.com:open-starlab/spaceEval.git
|
|
19
|
+
cd ./spaceEval
|
|
20
|
+
pip install -e .
|
|
21
|
+
```
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
Metadata-Version: 2.1
|
|
2
|
+
Name: openstarlab-spaceEval
|
|
3
|
+
Version: 0.0.1
|
|
4
|
+
Summary: openstarlab space eval package
|
|
5
|
+
Author-email: Calvin Yeung <yeung.chikwong@g.sp.m.is.nagoya-u.ac.jp>
|
|
6
|
+
License: Apache License 2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/open-starlab/
|
|
8
|
+
Classifier: Programming Language :: Python :: 3
|
|
9
|
+
Classifier: License :: OSI Approved :: Apache Software License
|
|
10
|
+
Classifier: Operating System :: OS Independent
|
|
11
|
+
Requires-Python: >=3.8
|
|
12
|
+
Description-Content-Type: text/markdown
|
|
13
|
+
License-File: LICENSE.md
|
|
14
|
+
Requires-Dist: pandas
|
|
15
|
+
Requires-Dist: numpy
|
|
16
|
+
Requires-Dist: matplotlib
|
|
17
|
+
Requires-Dist: scipy
|
|
18
|
+
Requires-Dist: tqdm
|
|
19
|
+
Requires-Dist: opencv-python
|
|
20
|
+
|
|
21
|
+
# OpenSTARLab SpaceEval package
|
|
22
|
+
|
|
23
|
+
## Introduction
|
|
24
|
+
The OpenSTARLab SpaceEval package is designed to provide simple and efficient way to visualize and estimate space evaluation for different sports. This package supports the data preprocessed by the OpenSTARLab PreProcessing package.
|
|
25
|
+
|
|
26
|
+
|
|
27
|
+
This package is continuously evolving to support future OpenSTARLab projects. If you have any suggestions or encounter any bugs, please feel free to open an issue.
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
- To install this package via PyPI
|
|
33
|
+
```
|
|
34
|
+
pip install openstarlab-spaceEval
|
|
35
|
+
```
|
|
36
|
+
- To install manually
|
|
37
|
+
```
|
|
38
|
+
git clone git@github.com:open-starlab/spaceEval.git
|
|
39
|
+
cd ./spaceEval
|
|
40
|
+
pip install -e .
|
|
41
|
+
```
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
LICENSE.md
|
|
2
|
+
README.md
|
|
3
|
+
pyproject.toml
|
|
4
|
+
openstarlab_spaceEval.egg-info/PKG-INFO
|
|
5
|
+
openstarlab_spaceEval.egg-info/SOURCES.txt
|
|
6
|
+
openstarlab_spaceEval.egg-info/dependency_links.txt
|
|
7
|
+
openstarlab_spaceEval.egg-info/requires.txt
|
|
8
|
+
openstarlab_spaceEval.egg-info/top_level.txt
|
|
9
|
+
spaceeval/__init__.py
|
|
10
|
+
spaceeval/sports/__init__.py
|
|
11
|
+
spaceeval/sports/main_class.py
|
|
12
|
+
spaceeval/sports/basketball/__init__.py
|
|
13
|
+
spaceeval/sports/basketball/application/__init__.py
|
|
14
|
+
spaceeval/sports/basketball/application/heatmap.py
|
|
15
|
+
spaceeval/sports/basketball/main_class_basketball/__init__.py
|
|
16
|
+
spaceeval/sports/basketball/main_class_basketball/main.py
|
|
17
|
+
spaceeval/sports/basketball/model_parameter/__init__.py
|
|
18
|
+
spaceeval/sports/basketball/models/BIMOS.py
|
|
19
|
+
spaceeval/sports/basketball/models/BMOS.py
|
|
20
|
+
spaceeval/sports/basketball/models/__init__.py
|
|
21
|
+
spaceeval/sports/basketball/utils/SportVU_IO.py
|
|
22
|
+
spaceeval/sports/basketball/utils/__init__.py
|
|
23
|
+
spaceeval/sports/basketball/utils/get_residual_param.py
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
# event/pyproject.toml
|
|
2
|
+
|
|
3
|
+
[build-system]
|
|
4
|
+
requires = ["setuptools>=42", "wheel"]
|
|
5
|
+
build-backend = "setuptools.build_meta"
|
|
6
|
+
|
|
7
|
+
[project]
|
|
8
|
+
name = "openstarlab-spaceEval"
|
|
9
|
+
version = "0.0.1"
|
|
10
|
+
description = "openstarlab space eval package"
|
|
11
|
+
readme = "README.md"
|
|
12
|
+
requires-python = ">=3.8"
|
|
13
|
+
authors = [
|
|
14
|
+
{ name="Calvin Yeung", email="yeung.chikwong@g.sp.m.is.nagoya-u.ac.jp" },
|
|
15
|
+
]
|
|
16
|
+
classifiers = [
|
|
17
|
+
"Programming Language :: Python :: 3",
|
|
18
|
+
"License :: OSI Approved :: Apache Software License",
|
|
19
|
+
"Operating System :: OS Independent",
|
|
20
|
+
]
|
|
21
|
+
dependencies = [
|
|
22
|
+
"pandas",
|
|
23
|
+
"numpy",
|
|
24
|
+
"matplotlib",
|
|
25
|
+
"scipy",
|
|
26
|
+
"tqdm",
|
|
27
|
+
"opencv-python"
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
license = { text = "Apache License 2.0" }
|
|
31
|
+
|
|
32
|
+
[tool.setuptools]
|
|
33
|
+
include-package-data = true
|
|
34
|
+
|
|
35
|
+
[tool.setuptools.packages.find]
|
|
36
|
+
where = ["."]
|
|
37
|
+
|
|
38
|
+
[project.urls]
|
|
39
|
+
Homepage = "https://github.com/open-starlab/"
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
@@ -0,0 +1,334 @@
|
|
|
1
|
+
import os
|
|
2
|
+
import numpy as np
|
|
3
|
+
from tqdm import tqdm
|
|
4
|
+
import matplotlib.pyplot as plt
|
|
5
|
+
import importlib.resources as pkg_resources
|
|
6
|
+
from ...basketball import utils
|
|
7
|
+
from PIL import Image
|
|
8
|
+
from ..models.BIMOS import BIMOS
|
|
9
|
+
from ..models.BMOS import BMOS
|
|
10
|
+
import datetime
|
|
11
|
+
from ..utils import SportVU_IO as sio
|
|
12
|
+
import glob
|
|
13
|
+
import cv2
|
|
14
|
+
|
|
15
|
+
COURT_SIZE = (28, 15) # Court dimensions in meters
|
|
16
|
+
EVENT_LABEL = 1
|
|
17
|
+
EVENT_LABELS = {
|
|
18
|
+
'nonevent': 0,
|
|
19
|
+
'pass': 1,
|
|
20
|
+
'catch and pass': 2,
|
|
21
|
+
'handoff catch and pass': 3,
|
|
22
|
+
'catch': 4,
|
|
23
|
+
'handoff pass': 5,
|
|
24
|
+
'handoff catch and handoff pass': 6,
|
|
25
|
+
'catch and handoff pass': 7,
|
|
26
|
+
'handoff catch': 8,
|
|
27
|
+
'2 point shot': 9,
|
|
28
|
+
'3 point shot': 10,
|
|
29
|
+
'turnover': 11
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
def plotCourt():
|
|
33
|
+
with pkg_resources.open_binary(utils, 'nba_court.png') as file:
|
|
34
|
+
img = Image.open(file)
|
|
35
|
+
img = img.copy()
|
|
36
|
+
|
|
37
|
+
plt.imshow(img, extent=[0, COURT_SIZE[0], 0, COURT_SIZE[1]], zorder=0)
|
|
38
|
+
plt.xlim(0, COURT_SIZE[0])
|
|
39
|
+
plt.ylim(0, COURT_SIZE[1])
|
|
40
|
+
|
|
41
|
+
def plot_heat_map_frame(save_path_folder, attValue, data,
|
|
42
|
+
include_player_velocities = True, BID=True, colorbar = True, title=True
|
|
43
|
+
,field_dimen = (COURT_SIZE[0],COURT_SIZE[1]), colormap = "Reds"):
|
|
44
|
+
|
|
45
|
+
att_x = []
|
|
46
|
+
att_y = []
|
|
47
|
+
dim_att = []
|
|
48
|
+
for a in range(5): # 5 attaquants
|
|
49
|
+
x = data[f'x_att{a}'].values[0]
|
|
50
|
+
y = data[f'y_att{a}'].values[0]
|
|
51
|
+
att_x.append(x)
|
|
52
|
+
att_y.append(y)
|
|
53
|
+
|
|
54
|
+
dim_att = [np.array(att_x), np.array(att_y)]
|
|
55
|
+
|
|
56
|
+
def_x = []
|
|
57
|
+
def_y = []
|
|
58
|
+
dim_def = []
|
|
59
|
+
for b in range(5):
|
|
60
|
+
x = data[f'x_def{b}'].values[0]
|
|
61
|
+
y = data[f'y_def{b}'].values[0]
|
|
62
|
+
def_x.append(x)
|
|
63
|
+
def_y.append(y)
|
|
64
|
+
|
|
65
|
+
dim_def = [np.array(def_x), np.array(def_y)]
|
|
66
|
+
|
|
67
|
+
dim_ball = []
|
|
68
|
+
x = data['x_ball'].values[0]
|
|
69
|
+
y = data['y_ball'].values[0]
|
|
70
|
+
dim_ball = np.array([x, y])
|
|
71
|
+
|
|
72
|
+
fig, ax = plt.subplots(figsize = (6,5))
|
|
73
|
+
fig.subplots_adjust(left = 0.01, bottom = 0.08, right = 0.99, top=0.95)
|
|
74
|
+
plt.text(14,-2,'[m]', ha = 'center')
|
|
75
|
+
|
|
76
|
+
ax.imshow(attValue, cmap = colormap, extent =(0, field_dimen[0], 0, field_dimen[1]), alpha=0.9)
|
|
77
|
+
if colorbar:
|
|
78
|
+
plt.colorbar(ax.imshow(attValue, cmap=colormap, extent=(0, field_dimen[0], 0, field_dimen[1]), alpha=0.9))
|
|
79
|
+
|
|
80
|
+
plotCourt()
|
|
81
|
+
|
|
82
|
+
ax.scatter(*dim_att, s = 100, edgecolor = 'r', c = 'white')
|
|
83
|
+
ax.scatter(*dim_def, s = 100, edgecolor = 'b', c = 'white')
|
|
84
|
+
ax.scatter(*dim_ball, s = 100, edgecolor = 'black', c = 'white')
|
|
85
|
+
ax.scatter(*dim_ball, s = 30, c = 'black')
|
|
86
|
+
|
|
87
|
+
if BID and data['ball_holder'].values[0] > 0 and data['ball_holder'].values[0] < 9:
|
|
88
|
+
bid_idx = int(data['ball_holder'].values[0] - 1)
|
|
89
|
+
ax.scatter(
|
|
90
|
+
data[f'x_att{bid_idx}'].values[0],
|
|
91
|
+
data[f'y_att{bid_idx}'].values[0],
|
|
92
|
+
s=17, facecolors='none', edgecolors='black'
|
|
93
|
+
)
|
|
94
|
+
|
|
95
|
+
if include_player_velocities:
|
|
96
|
+
for c in range(5):
|
|
97
|
+
plt.quiver(
|
|
98
|
+
data[f'x_att{c}'].values[0],
|
|
99
|
+
data[f'y_att{c}'].values[0],
|
|
100
|
+
data[f'vx_att{c}'].values[0],
|
|
101
|
+
data[f'vy_att{c}'].values[0],
|
|
102
|
+
angles='xy', scale_units='xy', scale=1, color='black'
|
|
103
|
+
)
|
|
104
|
+
|
|
105
|
+
for d in range(5):
|
|
106
|
+
plt.quiver(
|
|
107
|
+
data[f'x_def{d}'].values[0],
|
|
108
|
+
data[f'y_def{d}'].values[0],
|
|
109
|
+
data[f'vx_def{d}'].values[0],
|
|
110
|
+
data[f'vy_def{d}'].values[0],
|
|
111
|
+
angles='xy', scale_units='xy', scale=1, color='black'
|
|
112
|
+
)
|
|
113
|
+
|
|
114
|
+
if title:
|
|
115
|
+
plt.title(f"Game {data['gameID'].values[0]} - Attack {data['attackid'].values[0]} - Frame {data['f_id'].values[0]}")
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
if 'gameID' in data.columns:
|
|
119
|
+
game_id = data['gameID'].values[0]
|
|
120
|
+
else:
|
|
121
|
+
game_id = 'unknown'
|
|
122
|
+
|
|
123
|
+
if 'attackid' in data.columns:
|
|
124
|
+
attackid = data['attackid'].values[0]
|
|
125
|
+
else:
|
|
126
|
+
attackid = 'unknown'
|
|
127
|
+
|
|
128
|
+
if 'f_id' in data.columns:
|
|
129
|
+
frame_id = data['f_id'].values[0]
|
|
130
|
+
else:
|
|
131
|
+
frame_id = 'unknown'
|
|
132
|
+
|
|
133
|
+
filename = f"heatmap_game_{game_id}_attack_{attackid}_frame_{frame_id}.png"
|
|
134
|
+
save_path = f"{save_path_folder}/{filename}"
|
|
135
|
+
fig.savefig(save_path, dpi=300, bbox_inches='tight')
|
|
136
|
+
|
|
137
|
+
plt.close(fig)
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
def movie_from_images(image_files, output_file, frames_with_heatmap, fps=8, heatmap_duration_multiplier=10):
|
|
141
|
+
frame = cv2.imread(image_files[0])
|
|
142
|
+
height, width, _ = frame.shape
|
|
143
|
+
|
|
144
|
+
fourcc = cv2.VideoWriter_fourcc(*'mp4v')
|
|
145
|
+
out = cv2.VideoWriter(output_file, fourcc, fps, (width, height))
|
|
146
|
+
|
|
147
|
+
frame_indices = {}
|
|
148
|
+
for i, file in enumerate(image_files):
|
|
149
|
+
frame_number = int(file.split('_')[-1].split('.')[0])
|
|
150
|
+
frame_indices[file] = frame_number
|
|
151
|
+
|
|
152
|
+
for file in image_files:
|
|
153
|
+
img = cv2.imread(file)
|
|
154
|
+
frame_number = frame_indices[file]
|
|
155
|
+
|
|
156
|
+
if frame_number in frames_with_heatmap:
|
|
157
|
+
for _ in range(heatmap_duration_multiplier):
|
|
158
|
+
out.write(img)
|
|
159
|
+
else:
|
|
160
|
+
out.write(img)
|
|
161
|
+
|
|
162
|
+
out.release()
|
|
163
|
+
|
|
164
|
+
# Clean up by deleting image files after creating the movie
|
|
165
|
+
print("Video created at:", output_file)
|
|
166
|
+
|
|
167
|
+
if os.path.exists("figures"):
|
|
168
|
+
for file in glob.glob("figures/*"):
|
|
169
|
+
os.remove(file)
|
|
170
|
+
os.rmdir("figures")
|
|
171
|
+
print("Figures directory removed")
|
|
172
|
+
|
|
173
|
+
|
|
174
|
+
def plot_heat_map_sequence(model, data, save_path_folder, heatmap=True,
|
|
175
|
+
EVENT=True, JERSEY=True, BID=False, axis=False, title=True, field_dimen=(COURT_SIZE[0],COURT_SIZE[1])):
|
|
176
|
+
"""
|
|
177
|
+
Plots animation for a specific scene.
|
|
178
|
+
"""
|
|
179
|
+
|
|
180
|
+
def extract_date_info(gamename):
|
|
181
|
+
parts = gamename.split('_')
|
|
182
|
+
|
|
183
|
+
day = int(parts[1])
|
|
184
|
+
month = int(parts[0])
|
|
185
|
+
year = int(parts[2])
|
|
186
|
+
|
|
187
|
+
suffix = 'th' if 11 <= day <= 13 else {1: 'st', 2: 'nd', 3: 'rd'}.get(day % 10, 'th')
|
|
188
|
+
day_formatted = f"{day}{suffix}"
|
|
189
|
+
|
|
190
|
+
month_name = datetime.date(1900, month, 1).strftime('%b')
|
|
191
|
+
|
|
192
|
+
return day_formatted, month_name, str(year)
|
|
193
|
+
|
|
194
|
+
game_id = data['gameID'].values[0]
|
|
195
|
+
s_id = data['attackid'].values[0]
|
|
196
|
+
|
|
197
|
+
# Obtain date info
|
|
198
|
+
gamename = data['gamename'].values[0]
|
|
199
|
+
date, month, year = extract_date_info(gamename)
|
|
200
|
+
|
|
201
|
+
# Obtain team info
|
|
202
|
+
team_id_O = data['team_O'].values[0]
|
|
203
|
+
team_id_D = data['team_D'].values[0]
|
|
204
|
+
team_name_O = sio.load_team_name(team_id_O)
|
|
205
|
+
team_name_D = sio.load_team_name(team_id_D)
|
|
206
|
+
|
|
207
|
+
frames_with_heatmap = []
|
|
208
|
+
for i in tqdm(range(len(data))):
|
|
209
|
+
row_cumput = data.iloc[[i]].copy()
|
|
210
|
+
|
|
211
|
+
att_x = []
|
|
212
|
+
att_y = []
|
|
213
|
+
dim_att = []
|
|
214
|
+
for j in range(5): # 5 attaquants
|
|
215
|
+
x = row_cumput[f'x_att{j}'].values[0]
|
|
216
|
+
y = row_cumput[f'y_att{j}'].values[0]
|
|
217
|
+
att_x.append(x)
|
|
218
|
+
att_y.append(y)
|
|
219
|
+
|
|
220
|
+
dim_att = [np.array(att_x), np.array(att_y)]
|
|
221
|
+
|
|
222
|
+
def_x = []
|
|
223
|
+
def_y = []
|
|
224
|
+
dim_def = []
|
|
225
|
+
for j in range(5):
|
|
226
|
+
x = row_cumput[f'x_def{j}'].values[0]
|
|
227
|
+
y = row_cumput[f'y_def{j}'].values[0]
|
|
228
|
+
def_x.append(x)
|
|
229
|
+
def_y.append(y)
|
|
230
|
+
|
|
231
|
+
dim_def = [np.array(def_x), np.array(def_y)]
|
|
232
|
+
|
|
233
|
+
dim_ball = []
|
|
234
|
+
x = row_cumput['x_ball'].values[0]
|
|
235
|
+
y = row_cumput['y_ball'].values[0]
|
|
236
|
+
dim_ball = np.array([x, y])
|
|
237
|
+
|
|
238
|
+
frame_info = {
|
|
239
|
+
'dim_att': dim_att,
|
|
240
|
+
'dim_def': dim_def,
|
|
241
|
+
'dim_ball': dim_ball
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
if row_cumput['event_label'].values[0] not in [0, 4, 8]:
|
|
245
|
+
frames_with_heatmap.append(i)
|
|
246
|
+
if model == "BIMOS":
|
|
247
|
+
frame_info['attValue'] = BIMOS(row_cumput).values
|
|
248
|
+
|
|
249
|
+
else:
|
|
250
|
+
frame_info['attValue'] = BMOS(row_cumput).values
|
|
251
|
+
else:
|
|
252
|
+
frame_info['attValue'] = [[0] * 28 for _ in range(15)]
|
|
253
|
+
|
|
254
|
+
if EVENT:
|
|
255
|
+
frame_info['event_label'] = row_cumput['event_label'].values[0]
|
|
256
|
+
|
|
257
|
+
if JERSEY:
|
|
258
|
+
frame_info['jersey_number'] = row_cumput.filter(regex='^jersey_', axis=1).iloc[0].tolist()
|
|
259
|
+
|
|
260
|
+
# Create the figure and set up basic layout
|
|
261
|
+
fig, ax = plt.subplots(figsize=(6, 5))
|
|
262
|
+
fig.subplots_adjust(left=0.01, bottom=0.08, right=0.99, top=0.95)
|
|
263
|
+
plt.text(14, -2, '[m]', ha='center')
|
|
264
|
+
|
|
265
|
+
# Plot heatmap if enabled
|
|
266
|
+
if heatmap:
|
|
267
|
+
ax.imshow(frame_info['attValue'], cmap='Reds', vmin=0., vmax=1.,
|
|
268
|
+
extent=(0, field_dimen[0], 0, field_dimen[1]), alpha=0.9)
|
|
269
|
+
|
|
270
|
+
# Plot players and ball
|
|
271
|
+
ax.scatter(*frame_info['dim_att'], s=100, edgecolor='r', c="white")
|
|
272
|
+
ax.scatter(*frame_info['dim_def'], s=100, edgecolor='b', c="white")
|
|
273
|
+
ax.scatter(*frame_info['dim_ball'], s=30, c="black")
|
|
274
|
+
|
|
275
|
+
# Highlight ball possessor if enabled
|
|
276
|
+
if BID and row_cumput['ball_holder'].values[0] > 0 and row_cumput['ball_holder'].values[0] < 9:
|
|
277
|
+
bid_idx = int(row_cumput['ball_holder'].values[0] - 1)
|
|
278
|
+
ax.scatter(
|
|
279
|
+
row_cumput[f'x_att{bid_idx}'].values[0],
|
|
280
|
+
row_cumput[f'y_att{bid_idx}'].values[0],
|
|
281
|
+
s=60, facecolors='none', edgecolors='black'
|
|
282
|
+
)
|
|
283
|
+
|
|
284
|
+
# Add event labels if enabled
|
|
285
|
+
if EVENT and 'event_label' in frame_info:
|
|
286
|
+
ax.text(*frame_info['dim_ball'], f"{frame_info['event_label']}", fontsize=8)
|
|
287
|
+
|
|
288
|
+
# Add jersey numbers if enabled
|
|
289
|
+
if JERSEY and 'jersey_number' in frame_info:
|
|
290
|
+
for j in range(10):
|
|
291
|
+
jersey_number = int(frame_info["jersey_number"][j])
|
|
292
|
+
if j < 5: # Attacking team
|
|
293
|
+
x, y = frame_info['dim_att'][0][j], frame_info['dim_att'][1][j]
|
|
294
|
+
else: # Defending team
|
|
295
|
+
x, y = frame_info['dim_def'][0][j-5], frame_info['dim_def'][1][j-5]
|
|
296
|
+
|
|
297
|
+
ax.text(x, y, f'{jersey_number}',
|
|
298
|
+
fontsize=8, ha='center', va='center')
|
|
299
|
+
|
|
300
|
+
|
|
301
|
+
fid_str = str(i).zfill(3)
|
|
302
|
+
# Add title based on configuration
|
|
303
|
+
if title:
|
|
304
|
+
# Detailed title with team names and date
|
|
305
|
+
ax.set_title('')
|
|
306
|
+
ax.text(0.08, 1.025, team_name_O, color='red', fontsize=12, ha='center', transform=ax.transAxes)
|
|
307
|
+
ax.text(0.17, 1.025, 'vs.', color='black', fontsize=12, ha='center', transform=ax.transAxes)
|
|
308
|
+
ax.text(0.25, 1.025, team_name_D, color='blue', fontsize=12, ha='center', transform=ax.transAxes)
|
|
309
|
+
ax.text(0.65, 1.025, f"{date} {month}. {year} - Frame {fid_str}",
|
|
310
|
+
color='black', fontsize=12, ha='center', transform=ax.transAxes)
|
|
311
|
+
else:
|
|
312
|
+
# Simple title with game info and event type
|
|
313
|
+
ax.set_title(f'Game {game_id} - Attack {s_id} - Frame {fid_str}')
|
|
314
|
+
|
|
315
|
+
# Hide axis if not needed
|
|
316
|
+
if not axis:
|
|
317
|
+
plt.xticks([])
|
|
318
|
+
plt.yticks([])
|
|
319
|
+
|
|
320
|
+
# Save the frame and close the plot
|
|
321
|
+
# Add the court background
|
|
322
|
+
plotCourt()
|
|
323
|
+
|
|
324
|
+
if not os.path.exists("figures"):
|
|
325
|
+
os.makedirs("figures")
|
|
326
|
+
plt.savefig(f"figures/frame_{game_id}_{s_id}_{fid_str}.png")
|
|
327
|
+
plt.close()
|
|
328
|
+
|
|
329
|
+
image_files = sorted(glob.glob(f"figures/frame_{game_id}_{s_id}_*.png"))
|
|
330
|
+
print(image_files)
|
|
331
|
+
video_name = f"{save_path_folder}/space_evaluation_{game_id}_{s_id}.mp4"
|
|
332
|
+
movie_from_images(image_files=image_files, output_file=video_name, frames_with_heatmap = frames_with_heatmap)
|
|
333
|
+
|
|
334
|
+
|
|
File without changes
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
from ..models.BIMOS import BIMOS
|
|
2
|
+
from ..models.BMOS import BMOS
|
|
3
|
+
import os
|
|
4
|
+
import gdown
|
|
5
|
+
import zipfile
|
|
6
|
+
|
|
7
|
+
from ..application.heatmap import plot_heat_map_frame, plot_heat_map_sequence
|
|
8
|
+
|
|
9
|
+
class space_model_basketball:
|
|
10
|
+
def __init__(self, model_name):
|
|
11
|
+
"""
|
|
12
|
+
Initializes the class with model name and ensures the required file is downloaded.
|
|
13
|
+
|
|
14
|
+
:param model_name: str, the name of the model (e.g., "BIMOS", "BMOS")
|
|
15
|
+
:param file_id: str, the Google Drive file ID
|
|
16
|
+
:param dest_path: str, the local path where the file will be saved
|
|
17
|
+
"""
|
|
18
|
+
self.model_name = model_name
|
|
19
|
+
|
|
20
|
+
def plot_heat_map_frame(self, save_path_folder, data, *args, **kwargs):
|
|
21
|
+
|
|
22
|
+
if self.model_name == "BIMOS":
|
|
23
|
+
attValues = BIMOS(data).values
|
|
24
|
+
|
|
25
|
+
if self.model_name == "BMOS":
|
|
26
|
+
attValues = BMOS(data).values
|
|
27
|
+
|
|
28
|
+
plot_heat_map_frame(save_path_folder, attValues, data, *args, **kwargs)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def plot_heat_map_sequence(self, data, save_path_folder,*args, **kwargs):
|
|
32
|
+
|
|
33
|
+
if self.model_name == "BIMOS":
|
|
34
|
+
model = "BIMOS"
|
|
35
|
+
|
|
36
|
+
if self.model_name == "BMOS":
|
|
37
|
+
model = "BMOS"
|
|
38
|
+
|
|
39
|
+
plot_heat_map_sequence(model, data, save_path_folder,*args, **kwargs)
|
|
40
|
+
|
|
File without changes
|