Created
July 20, 2018 11:24
-
-
Save Ricocotam/385ce65d5111e261da11ca6d564db35b to your computer and use it in GitHub Desktop.
AMC to CSV parser for CMU dataset
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from itertools import chain | |
from collections import namedtuple | |
# Comes from : https://github.com/eric-heiden/mocap-roboschool-demo/blob/master/mocap_demo.py line 19-35 | |
def get_frames(filename): | |
# filename : amc file | |
frames = [] # list of dicts {property: value(s)} | |
current_frame = {} | |
with open(filename) as amc_file: | |
for i, line in enumerate(amc_file): | |
if i < 3: | |
continue | |
if line.startswith('root'): | |
if len(current_frame) > 0: | |
frames.append(current_frame) | |
current_frame = {} | |
split = line.split(' ') | |
if len(split) <= 1: | |
continue | |
current_frame[split[0]] = np.array([float(x) for x in split[1:]]) | |
if len(current_frame) > 0: | |
frames.append(current_frame) | |
return frames | |
frames = get_frames("save.amc") | |
to_app = ["_x", "_y", "_z", "_rx", "_ry", "_rz"] | |
names = [] | |
for k, v in frames[0].items(): | |
for i in range(len(v)): | |
names.append(k + to_app[i]) | |
State = namedtuple("State", names) | |
states = map(lambda s: state(*itertools.chain(*s.values())), frames) | |
df = pd.DataFrame(states, State._fields) | |
df.to_csv("save.csv") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment