convert_poses.py
Go to the documentation of this file.
00001 #!/usr/bin/env python
00002 
00003 from __future__ import print_function
00004 import yaml
00005 import argparse
00006 import sys
00007 
00008 def main():
00009     parser = argparse.ArgumentParser(description='Convert old poses to new motion format.')
00010     parser.add_argument('infile', nargs='?',
00011                         help='input poses parameter file [default: stdin]',
00012                         default='/dev/stdin')
00013     parser.add_argument('outfile', nargs='?',
00014                         help='output poses parameter file [default: stdout]',
00015                         default='/dev/stdout')
00016 
00017     args = parser.parse_args()
00018 
00019     with open(args.infile) as f:
00020         poses = yaml.load(f.read())
00021 
00022     if poses is None:
00023         print("uh oh, nothing could be read from the input :(", file=sys.stderr)
00024         return
00025 
00026     for n, toplevel in poses.iteritems():
00027         if 'poses' not in toplevel:
00028             print("no poses to convert, I'm done here.", file=sys.stderr)
00029             return
00030         if not 'motions' in toplevel:
00031             toplevel['motions'] = {}
00032         for pn, pose in toplevel['poses'].iteritems():
00033             print("converting pose '{}'".format(pn), file=sys.stderr)
00034             joints, positions = [list(x) for x in zip(*pose.items())]
00035             points = {'positions': positions, 'time_from_start': 0.0}
00036             toplevel['motions'][pn] = {'joints': joints, 'points': [points]}
00037         del toplevel['poses']
00038 
00039     print("writing to output file", file=sys.stderr)
00040     with open(args.outfile, "w") as f:
00041         yaml.dump(poses, f)
00042     print("finished! You're all set.", file=sys.stderr)
00043 
00044 if __name__ == "__main__":
00045     main()


play_motion
Author(s): Paul Mathieu
autogenerated on Wed Aug 26 2015 15:29:25