-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmotion.py
42 lines (29 loc) · 1.08 KB
/
motion.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
import numpy as np
def replace_blank(array):
return np.where(array == '', '0.0', array)
def get_exist_frames(data_1d):
frames = np.where(data_1d != 0.0)[0]
return frames
def extract_motion(csv_data, name):
str_data = [row for row in csv_data if row[0] == name]
str_array = np.array(str_data)
str_array = replace_blank(str_array)
float_array = str_array.astype(float)
return float_array[:, 2:]
def reshape_to_3d(motion_2d):
num_frames = motion_2d.shape[0]
return np.reshape(motion_2d, (num_frames, 21, 3))
def reshape_to_2d(motion_3d):
num_frames = motion_3d.shape[0]
return np.reshape(motion_3d, (num_frames, 63))
class Motion:
def __init__(self, csv_data, name):
self.name = name
self.data = reshape_to_3d(extract_motion(csv_data, name))
def write_csv(self, writer):
data_2d = reshape_to_2d(self.data).tolist()
num_frames = self.data.shape[0]
for frame in range(1, num_frames + 1):
row = [self.name, str(frame)]
row += data_2d[frame - 1]
writer.writerow(row)