scripts.tools

Subpackages

Author: Carmen Meinson

singleton(cls)
Config()

Authors: Carmen Meinson, Jason Ho and Oluwaponmile Femi-Sunmaila

class View(head_screen_top: bool = True, hidden: bool = False)

Bases: object

update_display_element(name: str, update_args: Dict[str, str] = {}) None

Updates a display element, e.g. area of interest element, by passing in updated arguments to update its attributes. If the display element class is not already initialised, then it also initialises the class.

Parameters
  • name (str) – Reference name of the DisplayElement class handled by the View

  • update_args (Dict[str, str]) – Keyword arguments to be passed into the DisplayElement class’ update method

update_display(frame: numpy.ndarray) None

Takes an image object and loops through all activated DisplayElements, running their update_display method allowing them to draw to the image

Parameters

frame (np.ndarray) – image object for the DisplayElement instances to draw to

hide() None
show() None
close()
was_closed_by_user() bool
get_frame_size() Tuple[int, int]

Author: Jason Ho

class DisplayElement

Bases: object

update(**kwargs) None

Takes in parameters and updates the DisplayElement’s attributes accordingly.

update_display(image) None

Takes a cv2 image object and updates the image, adding in extra display features, such as the area of interest or extremity circles.

class ExerciseDisplayElement

Bases: scripts.tools.display_element.DisplayElement

update_display(image) None

Takes a cv2 image object and updates the image, adding in the information for the activated exercises and the number of repeats.

update(exericses_repeats_dict: Dict[str, int]) None

Takes in parameters and updates the ExerciseDisplayElement’s attributes accordingly.

Parameters

exericses_repeats_dict (Dict[str, int]) – Dictionary of exercises to display with info about number of repeats

class ExtremityCirclesElement

Bases: scripts.tools.display_element.DisplayElement

update_display(image: numpy.ndarray) None

Takes an image object and updates the image, adding in the extremity circles representing the extremity triggers, including its state and repeats.

Parameters

image (np.ndarray) – Current frame being processed

update(extremity_circles_dict: Dict[str, Tuple]) None

Takes in parameters and updates the ExtremityCirclesElement’s attributes accordingly.

Parameters

extremity_circles_dict (Dict[str, Tuple]) – Dictionary of extremity triggers to display with info about coordinates, activation and repeats

class AreaOfInterestElement(height: int, width: int)

Bases: scripts.tools.display_element.DisplayElement

update_display(image) None

Takes a cv2 image object and updates the image, adding in the area of interest.

update(width_spacing: Optional[float] = None, height_spacing: Optional[float] = None) None

Takes in parameters and updates the AreaOfInterestElement’s attributes accordingly. If no parameters are given AOI is no longer displayed

class InAirKeyboardElement

Bases: scripts.tools.display_element.DisplayElement

update(buttons: dict, hovered_keys: set, clicked_keys: set, ask_kita: bool)

Takes in parameters and updates the DisplayElement’s attributes accordingly.

update_display(image) None

Takes a cv2 image and draws all the keyboard buttons, with different colours being used for keys which have been hovered over or clicked.

draw_buttons(overlay)
draw_ask_kita_indicator(overlay)
draw_button(overlay, x, y, w, h, text_size, bg_colour, text, text_colour)
class NoseBoxElement(height: int, width: int)

Bases: scripts.tools.display_element.DisplayElement

update_display(image) None

Takes a cv2 image object and updates the image, adding in the nose box.

update(nose_box_size, nose_point, nose_box_centre) None

Takes in parameters and updates the nosebox’s attributes accordingly. If no parameters are given the nosebox is no longer displayed

class ActiveModeNameElement

Bases: scripts.tools.display_element.DisplayElement

Display Element for an active mode name.

update_display(image) None

Takes a cv2 image object and updates the image with the name of the active mode.

update(name) None

Takes in new mode name. :param name: New mode name :type name: str :return: None :rtype: None

class FaceBoxElement

Bases: scripts.tools.display_element.DisplayElement

update_display(image) None

Takes a cv2 image object and updates the image, adding a facebox boundary (rectangle) in the frame.

update(tl: Optional[numpy.array] = None, br: Optional[numpy.array] = None) None

Update topLeft & Bottom right coordinate for boundary box

drawBox(image)
class HeadPosElement

Bases: scripts.tools.display_element.DisplayElement

update_display(image) None

Takes a cv2 image object and updates the image, adding headVector in the frame with (ROLL, PITCH, YAW) info.

update(headInfo: Optional[numpy.array] = None, headTl: Optional[numpy.array] = None, headBr: Optional[numpy.array] = None) None

Update information about head Roll, Pitch, Yaw

drawHeadPos(frame)
draw_text(img, *, text, uv_top_left, color=(255, 255, 255), fontScale=0.5, thickness=1, fontFace=0, outline_color=(0, 0, 0), line_spacing=1.5)

Draws multiline with an outline.

class FaceLandMarkElement

Bases: scripts.tools.display_element.DisplayElement

update_display(image) None

Takes a cv2 image object and updates the image, adding landmark points in the frame

update(landmarks: Optional[tuple[numpy.array]] = (), headTl: Optional[numpy.array] = None, headBr: Optional[numpy.array] = None) None

Update information about head Roll, Pitch, Yaw

drawLandMarks(frame)
class EyeGazeElement

Bases: scripts.tools.display_element.DisplayElement

update_display(image) None

Takes a cv2 image object and updates the image, draw gazeVector in the frame

update(headTl: Optional[numpy.array] = None, headBr: Optional[numpy.array] = None, landmarks: Optional[tuple[numpy.array]] = (), gaze: Optional[numpy.array] = None) None

Takes in parameters and updates the DisplayElement’s attributes accordingly.

drawGaze(frame)

Author: Carmen Meinson

class Camera

Bases: object

read() numpy.ndarray
close() NoReturn

JSON Editors

Author: Oluwaponmile Femi-Sunmaila

class JSONEditor(path: str, dynamic_path: Optional[bool] = False, iter_type: Optional[str] = None)

Bases: object

get_all_data() Dict[str, Any]

Retrieves the data stored in the JSONEditor object, reflects all unsaved changes made to the JSON file.

Returns

The data stored in the JSONEditor Object.

Return type

Dict[str, Any]

get_data(path: str) Dict[str, Any]

Retrieves some data stored in the JSON file.

Parameters

path (str) – The location of the JSON object to be read.

Returns

The retrieved data from the JSON file.

Return type

[Dict]

update(path: str, val: str) None

Updates the data JSON file.

Parameters
  • path (str) – The gesture to be added to the JSON

  • val (Any) – The value that is being added to the JSON

dynamic_update(path: str, val: str) None

Updates the data JSON file.

Parameters
  • path (str) – The gesture to be added to the JSON

  • val (Any) – The value that is being added to the JSON

add(path: str, val: Any, key: str)
save() None

Saves all changed made to the JSON file.

Author: Oluwaponmile Femi-Sunmaila

class ConfigEditor

Bases: scripts.tools.json_editors.json_editor.JSONEditor

Class that handles the reading/writing of the config JSON

get_activated_gesture_names(gesture_type: str) list[str]

Gets all the names of the activated gestures in the JSON.values.

Parameters

gesture_type – Specifies whether the gestures are “extremity_triggers”

or “exercises”. :type gesture_type: str :return: A list of all the activated gestures. :rtype: list

get_activated_gestures(gesture_type: str) Dict[str, Any]

Gets all the information of activated gestures.

Parameters

gesture_type – Specifies whether the gestures are “extremity_triggers”

or “exercises”. :type gesture_type: str :return: A dictionary containing all the activated gestures and their attributes. :rtype: Dict

Author: Oluwaponmile Femi-Sunmaila

class EventEditor

Bases: scripts.tools.json_editors.json_editor.JSONEditor

Class that handles the reading/writing of the event JSON

Events should be of the form event_name : {

type : EventClassName args : {} bodypart_names_to_type : {bodypart_name : type} triggers: {

trigger_name : (trigger_class, trigger_function)

}

}

remove(path)
add(path, event)

Adds A Gesture to the event JSON

validate_event(event)

Author: Oluwaponmile Femi-Sunmaila

class GestureEditor

Bases: scripts.tools.json_editors.json_editor.JSONEditor

Class that handles the reading/writing of the gesture JSON

Gestures should be of the form {

gesture_name{

primitive_name : bool, primitive_name : bool, …,

}

}

get_all_data() Dict[str, Any]

Use this to get all gestures

Returns

The contents of the JSON file, with all primitives being their corresponding python objects.

Return type

Dict[str, Dict[str]]

get_data(path: str) Set[scripts.core.gesture_factory.Primitive]

Gets all the primitives of a specified gesture.

Parameters

path (str) – The path to the event to retrieve.

Returns

A set of primitives representing the gesture.

Return type

Set[Primitive]

remove(path)
add(path, gesture)

Adds A Gesture to the gesture JSON

validate_gesture(gesture)

Author: Oluwaponmile Femi-Sunmaila

class ModeEditor

Bases: scripts.tools.json_editors.json_editor.JSONEditor

Class that handles the reading of the mode_controller JSON

remove(path)
add(path, value)

Module contents