Python
Parsing MoCap Data


return to main index

Related Topic

    Python & RfM: Rendering MoCap Data




Introduction

Motion capture (MoCap) files contain XYZ coordinate data that can be used for a variety of purposes in computer graphics. The Motion Capture Lab of the Advanced Computing Center for the Arts and Design, Ohio State University, have kindly made available a large number of mocap data files in a range of formats.
    http://accad.osu.edu/research/mocap/mocap_data.htm

This tutorial provides the python code for two classes that can read such data in TXT format. Such files have the following format.

Field  Time     C7:X     C7:Y    C7:Z    CLAV:X  CLAV:Y  CLAV:Z  LANK:X  LANK:Y  LANK:Z
1      0.0000   -62.944  31.271  1378.1  128.62  27.814  1332.7  9.2447  306.52  98.154    
2      0.0083   -62.944  31.271  1378.1  129.1   27.252  1333.2  9.1643  306.44  98.074
3      0.0167   -62.944  31.271  1378.1  129.34  27.091  1333.6  9.1643  306.36  97.993

The first line of text lists the names (identifiers) of the mocap markers. Each marker is specified three times, once for each of ite x, y and z values. For example,

    CLAV:X
    CLAV:Y
    CLAV:Z

If there are 40 markers there will be 120 xyz coordinates listed on each line of a TXT file. The tags named 'Field' and 'Time' are not the names of markers and, therefore, for the purpose of reading a mocap data file their values can be ignored. There might be several thousands of lines of coordinates in a mocap file. The process of reading and storing mocap data is as follows.

  1. Open and read all the lines of text from a mocap file into a python list.
  2. Remove the first item in the list and extract the names of the markers.
  3. For each name get an instance of the MoCapMarker class.
  4. For each item in the list,
            read the data in groups of three (x,y,z) and assign the values to a MoCapMarker marker.
    Instances of the MoCapMarker class append the xyz data to their own ('data') list.

The MoCap Classes

Listing 1 provides the code for the mocap classes. The class named MoCapMarker maintains a list named 'data' and provides a few methods for setting and getting xyz values stored in the list.

The MoCapDB class (mocap_db.py) is responsible for reading a TXT file, converting its lines of text into a list, creating instances of the MoCapMarker class and passing them xyz values to store. It also has a few methods for getting lists of xyz values from its database.



Using the MoCapDB Class

1.   Download one of the TXT files from the Motion Capture Lab.
2.   Save the code in listing 1 as mocap_db.py.
3.   In the same directory as mocap_db.py save a python file containing the following code.


from mocap_db import MoCapDB
  
scene_scale = 0.01
db = MoCapDB('PATH_TO_MOCAP_DATA_FILE', scene_scale)
  
markerID = 2
start = 1
end = 10
step = 1
  
coords = db.getMarkerData(markerID, start, end, step)
print coords

Execute the python script and you will see a list of xyz values for the third marker (index 2) from frame 1 to frame 10 in 1 frame steps.

The tutorial Python & RfM: Rendering MoCap Data demonstrate how the MoCapDB class can be sub-classed to provide output for Maya and Pixar's RenderMan for Maya.





© 2002- Malcolm Kesson. All rights reserved.