-
Notifications
You must be signed in to change notification settings - Fork 8
/
demo.py
135 lines (123 loc) · 3.35 KB
/
demo.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import numpy as np
import analysis_functions
import argparse
from pathlib import Path
OPTIONS = [
"visualize_3d_strokes",
"visualize_2d_strokes",
"animate_3d_path",
"bounce_heatmap",
"plot_3d_point",
"plot_trajectory",
]
def main(args):
"""
Creates an "analyzer" object for visualization of processed video data.
"""
if not args.viztype in OPTIONS:
print("Invalid vizualization chosen, choose from: ", str(OPTIONS))
raise
vidname = args.video_name
c1 = np.load(
str(
Path.joinpath(
Path(__file__).parents[0].resolve(), "data/" + vidname + "/c1.npy"
)
)
)
c2 = np.load(
str(
Path.joinpath(
Path(__file__).parents[0].resolve(), "data/" + vidname + "/c2.npy"
)
)
)
ball_pos1 = np.load(
str(
Path.joinpath(
Path(__file__).parents[0].resolve(),
"data/" + vidname + "/ballpath1.npy",
)
)
)
param1 = np.load(
str(
Path.joinpath(
Path(__file__).parents[0].resolve(), "data/" + vidname + "/param1.npy"
)
)
)
height1 = param1[0]
width1 = param1[1]
fps1 = param1[2]
ball_pos2 = np.load(
str(
Path.joinpath(
Path(__file__).parents[0].resolve(),
"data/" + vidname + "/ballpath2.npy",
)
)
)
param2 = np.load(
str(
Path.joinpath(
Path(__file__).parents[0].resolve(), "data/" + vidname + "/param2.npy"
)
)
)
height2 = param2[0]
width2 = param2[1]
fps2 = param2[2]
analyzer = analysis_functions.analyzer(
height1,
width1,
height2,
width2,
c1,
c2,
np.transpose(ball_pos1),
np.transpose(ball_pos2),
fps1,
)
# Available functions to run:
if args.viztype == "visualize_3d_strokes":
analyzer.visualize_3d_strokes(
args.pnbr
) # Plots one stroke at a time in 3d in point nbr pnbr
elif args.viztype == "visualize_2d_strokes":
analyzer.visualize_2d_strokes(
args.pnbr
) # Plots one stroke at a time in 2d in point nbr pnbr
elif args.viztype == "animate_3d_path":
analyzer.animate_3d_path() # Animates the 3d path taken in the whole video
elif args.viztype == "bounce_heatmap":
analyzer.bounce_heatmap() # Plots a heatmap of the detected bounces
elif args.viztype == "plot_3d_point":
analyzer.plot_3d_point(args.pnbr) # Plots the trajectory of point pnbr
else:
analyzer.plot_trajectory(
args.pnbr
) # Plots all trajectories from camera 1/2 perspective
if __name__ == "__main__":
parser = argparse.ArgumentParser()
parser.add_argument(
"--video_name",
type=str,
required=True,
help="Name of video used in processing.",
)
parser.add_argument(
"--viztype",
type=str,
required=True,
help="Type of visualization to run.",
)
parser.add_argument(
"--pnbr",
type=int,
required=False,
default=1,
help="The ID of the point to analyze in the video.",
)
args = parser.parse_args()
main(args)