def video_example(): target_folder = './video' try: os.makedirs(target_folder) except: pass lv0 = './data' lv1s = os.listdir(lv0) for lv1 in tqdm(lv1s, ncols=120): lv2s = os.listdir('/'.join([lv0, lv1])) asf_path = os.path.join(lv0, lv1, lv1 + '.asf') joints = reader.parse_asf(asf_path) im = Imitator(joints, SMPLModel('./model.pkl')) random.shuffle(lv2s) lv2 = None for lv2 in lv2s: if lv2.split('.')[-1] == 'amc': break amc_path = os.path.join(lv0, lv1, lv2) video_path = os.path.join(target_folder, '%s.avi' % lv2.split('.')[0]) motions = reader.parse_amc(amc_path) viewer = MeshViewer(im, motions) viewer.run(video_path=video_path, render_fps=-1, auto_run=True, auto_rerun=False, close_after_run=True)
def test_mesh(): subject = '13' im = Imitator(reader.parse_asf('./data/%s/%s.asf' % (subject, subject)), SMPLModel('./model.pkl')) sequence = '01' motions = reader.parse_amc('./data/%s/%s_%s.amc' % (subject, subject, sequence)) viewer = MeshViewer(im, motions) viewer.run()
self.asf_to_smpl_joints(translate) self.smpl_joints_to_mesh() def imitate(self, motion, translate=False): """ A warpper for `set_asf_motion` with a cool name. Prameter -------- translate: Whether add global translate to the mesh. Not recommended since the mesh is likely to move beyond the screen. """ self.set_asf_motion(motion, translate) if __name__ == '__main__': import reader import pickle subject = '01' im = Imitator(reader.parse_asf('./data/%s/%s.asf' % (subject, subject)), SMPLModel('./model.pkl')) sequence = '09' frame_idx = 0 motions = reader.parse_amc('./data/%s/%s_%s.amc' % (subject, subject, sequence)) theta = im.motion2theta(motions[frame_idx]) np.save('./pose.npy', theta)
from imitator import Imitator from smpl_np import SMPLModel from tqdm import tqdm import reader import os import numpy as np if __name__ == '__main__': target_folder = './pose' lv0 = './data' lv1s = os.listdir(lv0) for lv1 in tqdm(lv1s, ncols=120): lv2s = os.listdir('/'.join([lv0, lv1])) asf_path = '%s/%s/%s.asf' % (lv0, lv1, lv1) joints = reader.parse_asf(asf_path) im = Imitator(joints, SMPLModel('./model.pkl')) for lv2 in tqdm(lv2s): pose = [] if lv2.split('.')[-1] != 'amc': continue amc_path = '%s/%s/%s' % (lv0, lv1, lv2) save_path = '%s/%s' % (target_folder, lv2.split('.')[0] + '.npy') motions = reader.parse_amc(amc_path) for idx, motion in enumerate(motions): pose.append(im.motion2theta(motions[idx])) np.save(save_path, np.array(pose)) im.imitate(motions[0]) im.smpl.output_mesh('.'.join(save_path.split('.')[:-1]) + '.obj')