def __init__(self, bvh_filename): with open(bvh_filename) as f: mocap = Bvh(f.read()) MOCAP_TO_OSIM_HEIGHT = 0.94 / 17.6356 MOCAP_TO_OSIM_TRANSLATION = 1.27441 # the relative position of the left toes in the first frame of mocap data self.nframes = mocap.nframes self.frame_time = mocap.frame_time self.joints = {} self.joints['hip_l'] = np.array([ self.align_mocap_to_osim(eul_mocap, [0, 0, 21]) for eul_mocap in mocap.frames_joint_channels( 'LeftUpLeg', ['Xrotation', 'Yrotation', 'Zrotation']) ]) self.joints['hip_r'] = np.array([ self.align_mocap_to_osim(eul_mocap, [0, 0, -21]) for eul_mocap in mocap.frames_joint_channels( 'RightUpLeg', ['Xrotation', 'Yrotation', 'Zrotation']) ]) self.joints['knee_l'] = np.array([ self.align_mocap_to_osim(eul_mocap, [0, 0, 21]) for eul_mocap in mocap.frames_joint_channels( 'LeftLeg', ['Xrotation', 'Yrotation', 'Zrotation']) ])[:, :1] self.joints['knee_r'] = np.array([ self.align_mocap_to_osim(eul_mocap, [0, 0, -21]) for eul_mocap in mocap.frames_joint_channels( 'RightLeg', ['Xrotation', 'Yrotation', 'Zrotation']) ])[:, :1] self.joints['ankle_l'] = np.array([ self.align_mocap_to_osim(eul_mocap, [0, 0, 21]) for eul_mocap in mocap.frames_joint_channels( 'LeftFoot', ['Xrotation', 'Yrotation', 'Zrotation']) ])[:, :1] self.joints['ground_pelvis'] = np.array([ mocap.frames_joint_channels('Pelvis', [ 'Xrotation', 'Yrotation', 'Zrotation', 'Xposition', 'Yposition', 'Zposition' ]) ]).squeeze() # now make a few tweaks to the reference motion to zero out some joints self.joints[ 'ground_pelvis'][:, 3:] = self.joints['ground_pelvis'][:, 3:].dot( matrix_from_euler(0, -90, 0)) * MOCAP_TO_OSIM_HEIGHT self.joints['ground_pelvis'][:, 3] += MOCAP_TO_OSIM_TRANSLATION self.joints['ground_pelvis'][:, :3] = self.joints[ 'hip_l'][:, 1:] = self.joints['hip_r'][:, 1:] = 0
def test_frames_multi_channels(self): with open('tests/test_mocapbank.bvh') as f: mocap = Bvh(f.read()) rotations = mocap.frames_joint_channels('Head', ['Xrotation', 'Yrotation', 'Zrotation']) self.assertEqual(len(rotations), mocap.nframes)