c3d.Reader

class c3d.Reader(handle)

This class provides methods for reading the data in a C3D file.

A C3D file contains metadata and frame-based data describing 3D motion.

You can iterate over the frames in the file by calling read_frames() after construction:

>>> r = c3d.Reader(open('capture.c3d', 'rb'))
>>> for frame_no, points, analog in r.read_frames():
...     print('{0.shape} points in this frame'.format(points))
__init__(handle)

Initialize this C3D file by reading header and parameter data.

Parameters:
handle : file handle

Read metadata and C3D motion frames from the given file handle. This handle is assumed to be seek-able and read-able. The handle must remain open for the life of the Reader instance. The Reader does not close the handle.

Raises:
ValueError

If the processor metadata in the C3D file is anything other than 84 (Intel format).

Methods

__init__(handle) Initialize this C3D file by reading header and parameter data.
add_group(group_id, name, desc) Add a new parameter group.
check_metadata() Ensure that the metadata in our file is self-consistent.
first_frame()
get(group[, default]) Get a group or parameter.
get_bytes(key) Get a parameter value as a byte string.
get_float(key) Get a parameter value as a 32-bit float.
get_int16(key) Get a parameter value as a 16-bit signed integer.
get_int32(key) Get a parameter value as a 32-bit signed integer.
get_int8(key) Get a parameter value as an 8-bit signed integer.
get_string(key) Get a parameter value as a string.
get_uint16(key) Get a parameter value as a 16-bit unsigned integer.
get_uint32(key) Get a parameter value as a 32-bit unsigned integer.
get_uint8(key) Get a parameter value as an 8-bit unsigned integer.
last_frame()
parameter_blocks() Compute the size (in 512B blocks) of the parameter section.
read_frames([copy]) Iterate over the data frames from our C3D file handle.

Attributes

analog_labels
analog_rate
analog_used
point_labels
point_rate
point_scale
point_used
read_frames(copy=True)

Iterate over the data frames from our C3D file handle.

Parameters:
copy : bool

If False, the reader returns a reference to the same data buffers for every frame. The default is True, which causes the reader to return a unique data buffer for each frame. Set this to False if you consume frames as you iterate over them, or True if you store them for later.

Returns:
frames : sequence of (frame number, points, analog)

This method generates a sequence of (frame number, points, analog) tuples, one tuple per frame. The first element of each tuple is the frame number. The second is a numpy array of parsed, 5D point data and the third element of each tuple is a numpy array of analog values that were recorded during the frame. (Often the analog data are sampled at a higher frequency than the 3D point data, resulting in multiple analog frames per frame of point data.)

The first three columns in the returned point data are the (x, y, z) coordinates of the observed motion capture point. The fourth column is an estimate of the error for this particular point, and the fifth column is the number of cameras that observed the point in question. Both the fourth and fifth values are -1 if the point is considered to be invalid.