Pose

Description

Default class for poses, i.e. group of joints at a specific timestamp. A pose, in the motion sequence, is the equivalent of a frame in a video. The methods in this class are mainly handled by the methods in the class Sequence, but some of them can be directly accessed.

Initialisation

class classes.pose.Pose(timestamp=None)

Creates an instance from the class Pose and returns a Pose object, which stores Joint objects and a timestamp.

New in version 2.0.

Parameters:

timestamp (float, optional) – The timestamp of the pose (in seconds).

joints

A dictionary of joints, where the keys are the joint labels and the values are Joint instances.

Type:

OrderedDict(str: Joint)

timestamp

The timestamp of the pose (in seconds).

Type:

float

relative_timestamp

The timestamp of the pose, relative to the first pose of the sequence (in seconds).

Type:

float

Magic methods

Pose.__repr__()

Returns a string containing the timestamp, the relative timestamp and all the joints labels and coordinates from the Pose instance.

Returns:

A formatted string of the information contained in timestamp, relative_timestamp and joints.

Return type:

str

Example

>>> sequence = Sequence("C:/Users/Hadeel/Sequences/seq1/")
>>> pose = sequence.get_pose(4)
>>> print(pose)
Timestamp: 0.7673687
Relative timestamp: 0.7673687
Joints (21):
    Head: (0.2580389, 0.4354536, 2.449435)
    Neck: (0.2200405, 0.2870165, 2.452467)
    SpineShoulder: (0.2213234, 0.2103061, 2.444264)
    SpineMid: (0.224096, -0.02492883, 2.409717)
    SpineBase: (0.2265415, -0.3467222, 2.352579)
    ShoulderLeft: (0.08861267, 0.1529641, 2.387205)
    ElbowLeft: (0.05989294, -0.05652162, 2.338059)
    WristLeft: (0.1408673, -0.2341767, 2.213683)
    HandLeft: (0.1808563, -0.2797168, 2.203833)
    ShoulderRight: (0.3932458, 0.1480468, 2.420666)
    ElbowRight: (0.410402, -0.09375393, 2.338974)
    WristRight: (0.3219678, -0.2662066, 2.203344)
    HandRight: (0.2747259, -0.3047626, 2.200738)
    HipLeft: (0.1522616, -0.3320134, 2.309463)
    KneeLeft: (0.1468181, -0.8557156, 2.233713)
    AnkleLeft: (0.08108322, -1.155779, 2.15636)
    FootLeft: (0.1320685, -1.193715, 2.080927)
    HipRight: (0.2934242, -0.3502887, 2.319931)
    KneeRight: (0.2045003, -0.8930826, 2.275977)
    AnkleRight: (0.2089309, -1.175371, 2.194727)
    FootRight: (0.2288543, -1.20977, 2.095591)
Pose.__eq__(other)

Returns True if all the joints in the attribute joints are identical between the two Pose objects.

New in version 2.0.

Parameters:

other (Pose) – Another Pose object.

Public methods

Setter functions

Pose.set_timestamp(timestamp)

Sets the attribute timestamp of the pose (in seconds).

New in version 2.0.

Parameters:

timestamp – The timestamp of the pose (in seconds).

Getter functions

Pose.get_joint(joint_label)

Returns a joint object from the pose.

New in version 2.0.

Parameters:

joint_label (str) – The label of the joint (e.g. "Head").

Returns:

An instance of the class Joint.

Return type:

Joint

Pose.get_joint_labels()

Returns the labels of the joints in the joints attribute.

New in version 2.0.

Returns:

The list of joint labels.

Return type:

list(str)

Pose.get_timestamp()

Returns the attribute timestamp of the pose (in seconds).

New in version 2.0.

Returns:

The timestamp of the pose (in seconds).

Return type:

float

Pose.get_relative_timestamp()

Returns the attribute relative_timestamp of the pose, which is the timestamp relative to the first pose of the sequence (in seconds).

New in version 2.0.

Returns:

The timestamp of the pose relative to the first timestamp of the sequence, in seconds.

Return type:

float

Pose.get_copy()

Returns a deep copy of itself, containing deep copies of all the joints.

New in version 2.0.

Returns:

A deep copy of the Pose instance.

Return type:

Pose

Joints functions

Pose.add_joint(joint_label, joint, replace_if_exists=False)

Adds a Joint object to the pose.

New in version 2.0.

Parameters:
  • joint_label (str) – The label of the joint (e.g. "Head").

  • joint (Joint) – A joint object.

  • replace_if_exists (bool) – If False (default), the function will return an error if there is already a key with the name joint_label in the joints parameter. If True, the function will replace the existing value if it exists, without any warning message.

Pose.generate_average_joint(list_joints_to_average, new_joint_label, add_joint=True)

Generates and returns a joint that is located at the average position of the other joints.

New in version 2.0.

Parameters:
  • list_joints_to_average (list(Joint)) – A list containing the strings of the joints to average.

  • new_joint_label (str) – The label of the joint (e.g. "Head").

  • add_joint (bool, optional) – If set on True, the joint created is also added to the parameter joints of the current Pose instance. If set on False, the joint is only generated and returned.

Returns:

The average joint.

Return type:

Joint

Pose.remove_joint(joint_label)

Removes the specified joint from the pose.

New in version 2.0.

Parameters:

joint_label (str) – The label of the joint (e.g. "Head").

Pose.remove_joints(list_of_joint_labels)

Removes the specified joints from the pose.

New in version 2.0.

Parameters:

list_of_joint_labels (list(str)) – A list of labels of joints to remove.

Conversion functions

Pose.convert_to_table(use_relative_timestamp=False)

Returns a table (a list of lists) where the first row is the header, and the second row contains the values. The first column of the table contains the timestamps, while the subsequent columns, by sets of three, contain the coordinates of a joint on the x, y and z axes respectively. The output then resembles the table found in Tabled formats.

New in version 2.0.

Parameters:

use_relative_timestamp (bool, optional) – Defines if the timestamps used in the table are absolute (False) or relative to the first pose (True).

Returns:

A list of lists that can be interpreted as a table, containing headers and the values of the timestamps and the coordinates of the joints from the pose.

Return type:

list(list)

Pose.convert_to_json(use_relative_timestamp=False)

Returns a list ready to be exported in JSON. The structure followed by the dictionary is the same as the output dictionary from Kinect, for compatibility purposes. The output then resembles the table found in JSON formats.

New in version 2.0.

Parameters:

use_relative_timestamp (bool, optional) – Defines if the timestamps used in the table are absolute (False) or relative to the first pose (True).

Returns:

A list containing the data of the sequence, ready to be exported in JSON.

Return type:

list

Private methods

Pose._calculate_relative_timestamp(timestamp_first_pose, time_unit='s')

Calculates the timestamp relative to the first pose of the sequence. This function is typically called at the end of the initialisation of a new sequence (either by opening a file or performing a processing on an existing sequence), and sets a value to the attribute relative_timestamp.

New in version 2.0.

Parameters:
  • timestamp_first_pose (float) – The timestamp of the first pose of the sequence, in its original time unit.

  • time_unit (str, optional) –

    The time unit of the timestamps of the sequence. This parameter can take the following values: “ns”, “1ns”,
    ”10ns”, “100ns”, “µs”, “1µs”, “10µs”, “100µs”, “ms”, “1ms”, “10ms”, “100ms”, “s”, “sec”, “1s”, “min”, “mn”,

    ”h”, “hr”, “d”, “day”.

Pose._get_copy_with_empty_joints(use_relative_timestamp=False)

Creates a deep copy of the pose with a timestamp, and a joints with the same label joints as the original, but with the values set on None. The function then returns the copy.

New in version 2.0.

Parameters:

use_relative_timestamp (bool, optional) – Defines if the timestamps used in the table are absolute (False) or relative to the first pose (True).

Returns:

A Pose instance that is the deep copy of the original, but with all the values of the joints dictionary set on None.

Return type:

Pose