Graphic functions

Description

Functions to display and compare sequences graphically.

Shortcuts

While playing a sequence, the following keyboard shortcuts can perform some modifications.

First, the modifier keys A and B allow to modify a sequence independently of the other:

Modifiers

Modifier key

Action

_images/a.png

Applies the action to the first sequence only.

_images/b.png

Applies the action to the second sequence only.

_images/none.png

Applies the action to both sequences.

In the following shortcuts, the ones followed by an asterisk (*) can be applied to one of the sequences only by using a modifier.

General shortcuts

Operation

Key or key combination

Pause/Unpause

_images/space.png

Increase the display speed by 0.25

_images/%2B.png

Decrease the display speed by 0.25

_images/-.png

Next pose (manual or paused only)

_images/right.png

Previous pose (manual or paused only)

_images/left.png

Show/hide corrected joints*

_images/c.png

Show/hide bottom joints*

_images/i.png

Show/hide lines*

_images/l.png

Show/hide pose index

_images/p.png

Move the animation*

_images/left_click.png _images/plus.png _images/move.png
Size shortcuts

Operation

Key or key combination

Zoom in*

_images/scroll_up.png

Zoom out*

_images/scroll_down.png

Increase default joint size*

_images/ctrl.png _images/plus.png _images/scroll_up.png

Decrease default joint size*

_images/ctrl.png _images/plus.png _images/scroll_down.png

Increase hand joint size*

_images/alt.png _images/plus.png _images/scroll_up.png

Decrease hand joint size*

_images/alt.png _images/plus.png _images/scroll_down.png

Increase head joint size*

_images/ctrl.png _images/plus.png _images/alt.png _images/plus.png _images/scroll_up.png

Decrease head joint size*

_images/ctrl.png _images/plus.png _images/alt.png _images/plus.png _images/scroll_down.png

Increase line width*

_images/shift.png _images/plus.png _images/scroll_up.png

Decrease line width*

_images/shift.png _images/plus.png _images/scroll_down.png

Functions

graphic_functions.common_displayer(sequence1, sequence2=None, path_audio=None, path_video=None, position_sequences='side', position_video='superimposed', resolution=0.5, height_window_in_meters=3.0, full_screen=False, manual=False, start_pose=0, verbosity=1, **kwargs)

Common displayer function wrapped in all the other graphic functions. Allows to display one or two sequences, in a Pygame window, in a highly customizable way. A sequence can be displayed jointly with an audio file or a video file.

New in version 2.0.

Parameters:
  • sequence1 (Sequence) – A Sequence instance.

  • sequence2 (Sequence, optional) – A second, optional Sequence instance that can be displayed superimposed or next to the previous one, for comparison purposes.

  • path_audio (str, optional) – The path of an audio file (.wav format) to read with the Sequence instance(s).

  • path_video (str, optional) –

    The path of a video file (ending in .mp4) to read behind or next to the Sequence instance(s).

    Note

    The audio from the video will not be read. If you wish to hear audio, provide a .wav file in the parameter path_audio.

  • position_sequences (str, optional) – Defines if the sequences should be displayed next to each other ("side", default), or on top of each other ("superimposed").

  • position_video (str, optional) – Defines if the video should be displayed behind the sequence(s) ("superimposed", default), or next to the sequence(s) ("side")

  • resolution (tuple(int, int) or float or None, optional) –

    The resolution of the Pygame window that will display the Sequence instance(s). This parameter can be:

    • A tuple with two integers, representing the width and height of the window in pixels.

    • A float, representing the ratio of the total screen width and height (default: 0.5); for example, setting this parameter on 0.5 on a screen that is 1920 × 1080 pixels will create a window of 960 × 540 pixels.

    • None: in that case, the window will be the size of the screen.

  • height_window_in_meters (float, optional) – Defines the distance, in meters, represented by the vertical number of pixels of the window (by default: 3).

  • full_screen (bool, optional) – Defines if the window will be set full screen (True, default) or not.

  • manual (bool, optional) – If set on False (default), the poses of the Sequence will be displayed in real time. If set on True, the poses will be static, allowing the user to move to the next or previous pose using the right or left arrow keys, respectively.

  • start_pose (int, optional) – The index of the pose at which to start the sequence.

  • verbosity (int, optional) –

    Sets how much feedback the code will provide in the console output:

    • 0: Silent mode. The code won’t provide any feedback, apart from error messages.

    • 1: Normal mode (default). The code will provide essential feedback such as progression markers and current steps.

    • 2: Chatty mode. The code will provide all possible information on the events happening. Note that this may clutter the output and slow down the execution.

  • **kwargs (dict, optional) – A dictionary of optional arguments. See Keyword arguments.

graphic_functions.sequence_reader(sequence, path_audio=None, path_video=None, position_video='superimposed', resolution=0.5, height_window_in_meters=3.0, full_screen=False, start_pose=0, verbosity=1, **kwargs)

Displays the joints of the sequence in real time and loops back to the beginning when over.

Note

This function is a wrapper for the function common_displayer().

Parameters:
  • sequence (Sequence) – A Sequence instance.

  • path_audio (str, optional) – The path of an audio file (ending in .wav, .mp3 or .ogg) to read with the Sequence instance(s).

  • path_video (str, optional) – The path of a video file (ending in .mp4) to read behind or next to the Sequence instance(s).

  • position_video (str, optional) – Defines if the video should be displayed behind the sequence(s) ("background", default), or next to the sequence(s) ("side")

  • resolution (tuple(int, int) or float or None, optional) –

    The resolution of the Pygame window that will display the Sequence instance(s). This parameter can be:

    • A tuple with two integers, representing the width and height of the window in pixels.

    • A float, representing the ratio of the total screen width and height (default: 0.5); for example, setting this parameter on 0.5 on a screen that is 1920 × 1080 pixels will create a window of 960 × 540 pixels.

    • None: in that case, the window will be the size of the screen.

  • height_window_in_meters (float, optional) – Defines the distance, in meters, represented by the vertical number of pixels of the window (by default: 3).

  • full_screen (bool, optional) – Defines if the window will be set full screen (True, default) or not.

  • start_pose (int, optional) – The index of the pose at which to start the sequence.

  • verbosity (int, optional) –

    Sets how much feedback the code will provide in the console output:

    • 0: Silent mode. The code won’t provide any feedback, apart from error messages.

    • 1: Normal mode (default). The code will provide essential feedback such as progression markers and current steps.

    • 2: Chatty mode. The code will provide all possible information on the events happening. Note that this may clutter the output and slow down the execution.

  • **kwargs (dict, optional) – A dictionary of optional arguments. See Keyword arguments.

graphic_functions.sequence_comparer(sequence1, sequence2, path_audio=None, path_video=None, position_sequences='side', resolution=0.5, full_screen=False, manual=False, start_pose=0, verbosity=1, **kwargs)

Compares two sequences side by side or on top of each other.

New in version 2.0.

Note

This function is a wrapper for the function common_displayer().

Parameters:
  • sequence1 (Sequence) – A first Sequence instance.

  • sequence2 (Sequence) – A second Sequence instance.

  • path_audio (str, optional) – The path of an audio file (ending in .wav, .mp3 or .ogg) to read with the Sequence instance(s).

  • path_video (str, optional) – The path of a video file (ending in .mp4) to read behind or next to the Sequence instance(s).

  • position_sequences (str, optional) – Defines if the sequences should be displayed next to each other ("side", default), or on top of each other ("superimposed").

  • resolution (tuple(int, int) or float or None, optional) –

    The resolution of the Pygame window that will display the Sequence instance(s). This parameter can be:

    • A tuple with two integers, representing the width and height of the window in pixels.

    • A float, representing the ratio of the total screen width and height (default: 0.5); for example, setting this parameter on 0.5 on a screen that is 1920 × 1080 pixels will create a window of 960 × 540 pixels.

    • None: in that case, the window will be the size of the screen.

  • full_screen (bool, optional) – Defines if the window will be set full screen (True, default) or not.

  • manual (bool, optional) – If set on False (default), the poses of the Sequence will be displayed in real time. If set on True, the poses will be static, allowing the user to move to the next or previous pose using the right or left arrow keys, respectively.

  • start_pose (int, optional) – The index of the pose at which to start the sequence.

  • verbosity (int, optional) –

    Sets how much feedback the code will provide in the console output:

    • 0: Silent mode. The code won’t provide any feedback, apart from error messages.

    • 1: Normal mode (default). The code will provide essential feedback such as progression markers and current steps.

    • 2: Chatty mode. The code will provide all possible information on the events happening. Note that this may clutter the output and slow down the execution.

  • **kwargs (dict, optional) – A dictionary of optional arguments. See Keyword arguments.

graphic_functions.pose_reader(sequence, start_pose=0, resolution=0.5, full_screen=False, verbosity=1, **kwargs)

Reads a sequence and offers a manuel control over the poses, with the arrows of the keyboard.

New in version 2.0.

Parameters:
  • sequence (Sequence) – A Sequence instance.

  • start_pose (int, optional) – The index of the pose at which to start the sequence.

  • resolution (tuple(int, int) or float or None, optional) –

    The resolution of the Pygame window that will display the Sequence instance(s). This parameter can be:

    • A tuple with two integers, representing the width and height of the window in pixels.

    • A float, representing the ratio of the total screen width and height (default: 0.5); for example, setting this parameter on 0.5 on a screen that is 1920 × 1080 pixels will create a window of 960 × 540 pixels.

    • None: in that case, the window will be the size of the screen.

  • full_screen (bool, optional) – Defines if the window will be set full screen (True, default) or not.

  • verbosity (int, optional) –

    Sets how much feedback the code will provide in the console output:

    • 0: Silent mode. The code won’t provide any feedback, apart from error messages.

    • 1: Normal mode (default). The code will provide essential feedback such as progression markers and current steps.

    • 2: Chatty mode. The code will provide all possible information on the events happening. Note that this may clutter the output and slow down the execution.

  • **kwargs (dict, optional) – A dictionary of optional arguments. See Keyword arguments.

graphic_functions._process_events(animation, window_area, modif_this, modif_other, seq_num, manual, event, modifiers, steps, move_animation, verbosity=1)

For one animation, gets the user input and modifies the attributes of the animation accordingly.

New in version 2.0.

Parameters:
  • animation (GraphicSequence) – An instance of a GraphicSequence

  • window_area (WindowArea) – The WindowArea instance the mouse currently is in.

  • modif_this (int) – The Pygame integer code of a keyboard modifier key for this sequence (K_A for the first sequence, K_B for the second).

  • modif_other (int) – The Pygame integer code of a keyboard modifier key for the other sequence (K_B for the first sequence, K_A for the second).

  • seq_num (int) – The number of the animation (1 or 2).

  • manual (bool) – The value of the variable manual from the function common_displayer().

  • event (Pygame.event)) – A Pygame event.

  • modifiers (dict(int: bool)) – A dictionary containing the current state of the modifier keys (pressed or not).

  • steps (dict(str: float)) – A dictionary containing the incrementing steps for each parameter.

  • move_animation (dict or None) – An dictionary containing the starting position of the animation and the starting position of the mouse when a movement of the animation was initiated by the mouse, or None if no movement was initiated.

  • verbosity (int, optional) –

    Sets how much feedback the code will provide in the console output:

    • 0: Silent mode. The code won’t provide any feedback, apart from error messages.

    • 1: Normal mode (default). The code will provide essential feedback such as progression markers and current steps.

    • 2: Chatty mode. The code will provide all possible information on the events happening. Note that this may clutter the output and slow down the execution.

Returns:

manual – The variable manual from the function common_displayer(), that was passed as parameter.

Return type:

bool

Keyword arguments

The functions common_displayer(), sequence_reader(), sequence_comparer() and pose_reader() allow other arguments to be passed as keyword arguments, allowing for complete customisation of the display. These arguments can be passed as the other arguments, but given their large number, they are not defined in the docstring of the function; instead, they are defined in the table below.

For example, you can call:

>>> sequence = Sequence("C:/Users/Zoidberg/Recording/")
>>> sequence_reader(sequence, color_joint_default="red", line_width=4)

Note

Most of the following keyword arguments come in three variations: the first refers to both sequences, the second to the first sequence, and the last to the second sequence. For example, shape_joint sets the shape of the joints for both sequences (or the only sequence if only one is displayed), while shape_joint_seq1 will set the shape of the joints for the first sequence, and shape_joint_seq2 for the second sequence. The keyword arguments coming without variations

Keyword arguments

Keyword

Type

Description

Default value

background_color
background_color_seq1
background_color_seq2

tuple(int, int, int, int)
tuple(int, int, int)
str

The background color for the window (if only one sequence is displayed) or for one half of the window (if two sequences are displayed).

"black"

ignore_bottom
ignore_bottom_seq1
ignore_bottom_seq2

bool

Defines if to ignore the joints and lines located in the lower half of the body.

False

show_lines
show_lines_seq1
show_lines_seq2

bool

If set on True, the graphic sequence will include lines between certain joints, to create a skeleton. If set on False, only the joints will be displayed.

True

show_joint_corrected
show_joint_corrected_seq1
show_joint_corrected_seq2

bool

If set on True, the joints corrected by Sequence.correct_jitter() or Sequence.correct_zeros() will appear colored by color_joint_corrected.

True

shape_joint
shape_joint_seq1
shape_joint_seq2

str

The shape that the joints will have: "circle" (default) or "square".

"circle"

color_joint_default
color_joint_default_seq1
color_joint_default_seq2

tuple(int, int, int, int)
tuple(int, int, int)
str

The color of the joints.

"white"

color_joint_corrected
color_joint_corrected_seq1
color_joint_corrected_seq2

tuple(int, int, int, int)
tuple(int, int, int)
str

The color of the joints corrected by Sequence.correct_jitter() or Sequence.correct_zeros().

"sheen green"

color_line
color_line_seq1
color_line_seq2

tuple(int, int, int, int)
tuple(int, int, int)
str

The color of the lines between the joints.

"grey"

width_line
width_line_seq1
width_line_seq2

int

The width of the lines connecting the joints, in pixels.

1

size_joint_default
size_joint_default_seq1
size_joint_default_seq2

int

The radius (if shape_joint is set on “circle”) or width/height (if shape_joint is set on “square”), in pixels, of the joints not covered by size_joint_head and size_joint_hand.

10

size_joint_hand
size_joint_hand_seq1
size_joint_hand_seq2

int

The radius (if shape_joint is set on “circle”) or width/height (if shape_joint is set on “square”), in pixels, of the “HandRight” and “HandLeft” joints (Kinect) or the “HandOutRight” and “HandOutLeft” joints (Kualysis).

20

size_joint_head
size_joint_head_seq1
size_joint_head_seq2

int

The radius (if shape_joint is set on “circle”) or width/height (if shape_joint is set on “square”), in pixels, of the “Head” joint (Kinect) or the “HeadFront” joint (Kualysis).

50

scale_joint
scale_joint_seq1
scale_joint_seq2

float

Scaling factor for the size of the joints.

1

shift
shift_seq1
shift_seq2

tuple(int, int)

The number of pixels to shift the display of the joints from the first sequence on the horizontal and vertical axes, respectively.

(0, 0)

zoom_level
zoom_level_seq1
zoom_level_seq2

float

Defines the zoom level compared to the original view. A zoom level of 2 will make the joints appear twice as close.

1

speed

float

The speed at which to display the sequences.

1

font_color

tuple(int, int, int, int)
tuple(int, int, int)
str

The color of the font indicating the current pose and time marker.

"white"

show_progress

bool

If set on True, shows the current pose and timestamp in the bottom right corner.

True