https://github.com/ChrisWu1997/2D-Motion-Retargeting
Tip revision: f3454a1972a98b3a572f83c1c9ea0b0e5d9e7d00 authored by Rundi Wu on 28 December 2020, 02:08:07 UTC
Update README.md
Update README.md
Tip revision: f3454a1
preprocess.py
import os
import numpy as np
def main():
data_root = './mixamo_data'
for phase in ['train', 'test']:
phase_dir = os.path.join(data_root, phase)
character_names = os.listdir(phase_dir)
len_frames = 64 if phase == 'train' else 120
for char in character_names:
char_dir = os.path.join(phase_dir, char)
animation_names = os.listdir(char_dir)
for anim in animation_names:
anim_path = os.path.join(char_dir, anim, anim + '.npy')
animation = np.load(anim_path)
mot_dir = os.path.join(char_dir, anim, 'motions')
if not os.path.exists(mot_dir):
os.makedirs(mot_dir)
total_length = animation.shape[-1]
nr_motions = total_length // (len_frames // 2) - 1
for i in range(nr_motions):
save_path = os.path.join(mot_dir, '{}.npy'.format(i + 1))
window = animation[:, :, i * (len_frames // 2): i * (len_frames // 2) + len_frames]
np.save(save_path, window)
print(save_path, window.shape)
if __name__ == '__main__':
main()
