nicetoolbox.detectors.feature_detectors.kinematics.velocity_body

Velocity Body feature detector class for kinematics of the body.

Classes

VelocityBody

The VelocityBody class is a feature detector that computes the kinematics component.

class nicetoolbox.detectors.feature_detectors.kinematics.velocity_body.VelocityBody(config, io, data)[source]

The VelocityBody class is a feature detector that computes the kinematics component.

The VelocityBody feature detector accepts the human_pose component (body_joints) as itsprimary input, which is computed using the human_pose method detector. The kinematics component of this feature detector calculates the Euclidean distance between adjacent frames, essentially determining the velocity of body movement from one frame to the next.

Component: kinematics

components

A list containing the name of the component this class is

Type:

list

responsible for

kinematics:

algorithm

The name of the algorithm used to compute the kinematics component. velocity_body: the velocity of body movement from one frame to the next

Type:

str

predictions_mapping

A dictionary containing the mapping of body parts to their respective indices.

Type:

dict

camera_names

A list containing the names of the cameras used to capture the original input data.

Type:

list

bodyparts_list

A list containing the names of the body parts.

Type:

list

fps

The frames per second of the input data.

Type:

int

Setup input/output folders and data for the Kinematics feature detector.

This method initializes the Kinematics class by setting up the necessary configurations, input/output handler, and data. It also extracts the body_joints component and algorithm from the configuration and prepares the list of body parts. It supports handling of multiple cameras by loading the camera names from the pose configuration.

Parameters:
  • config (dict) – The configuration settings for the feature detector. It should include ‘input_detector_names’ key which contains joints component and algorithm.

  • io (object) – The input/output handler object. It should have a method ‘get_detector_output_folder’ which returns the output folder for the joints detector.

  • data (object) – The data object containing the input data. It should have an attribute ‘fps’ which represents the frames per second of the input data.

compute()[source]

Computes the kinematics component.

This method calculates the Euclidean distance between adjacent frames for each keypoint. It handles both 2D and 3D data. The method starts by loading the joint data from the input files. It then computes the differences between adjacent frames for each keypoint. A zero-filled frame is added at the beginning to match the original number of frames. Finally, the Euclidean distance for each keypoint between adjacent frames is computed. The computed differences are stored in a dictionary and saved to a compressed .npz file with the following structure:

  • displacement_vector_body_2d: A numpy array containing the computed differences

    for 2D data.

  • velocity_body_2d: A numpy array containing the computed velocity for 2D data.

  • displacement_vector_body_3d: A numpy array containing the computed differences

    for 3D data.

  • velocity_body_3d: A numpy array containing the computed velocity for 3D data.

  • data_description: A dictionary containing the data description for all of the

    above output numpy arrays. See the documentation of the output for more details.

Returns:

A dictionary containing the above mentioned parts of the

kinematics component.

Return type:

out_dict (dict)

post_compute(motion_velocity)[source]

Calculates the sum of movement per body part.

This method calculates the sum of movement per body part by averaging the motion velocity over the joint indices corresponding to each body part. It then concatenates the results for all body parts.

The method also checks for any [0,0,0] prediction using the check_zeros function from the check module.

Parameters:

motion_velocity (numpy.ndarray) – A 5D numpy array with shape (#persons, #cameras, #frames, #joints/keypoints, 1/velocity) representing the motion velocity.

Returns:

A 4D numpy array with shape

(#persons, #cameras, #frames, #bodyparts) representing the sum of movement per body part.

Return type:

bodypart_motion (numpy.ndarray)

visualization(out_dict)[source]

Creates visualizations for the computed kinematics component.

This method generates visualizations for the computed kinematics component. It checks if the output dictionary contains the keys ‘velocity_body_2d’ and ‘velocity_body_3d’. If these keys are present, their corresponding values are used to create the visualizations.

The method calculates the sum of movement per body part using the post_compute method. It then determines the global minimum and maximum values to define the y-limits of the graphs. Finally, it calls the visualize_mean_of_motion_magnitude_by_bodypart function from the kinematics_utils module to generate the visualizations.

Parameters:

out_dict (dict) – The output dictionary containing the computed kinematics component. It should contain the keys ‘velocity_body_2d’ and/or ‘velocity_body_3d’.