sign_language_translator.vision.landmarks.display module
- class sign_language_translator.vision.landmarks.display.MatPlot3D[source][source]
Bases:
object- classmethod animate(frames: Sequence[Sequence[Tuple[float, float, float]]] | ndarray[Any, dtype[_ScalarType_co]], line_indexes: Sequence[Sequence[int]] | None = None, line_colors: Sequence[Tuple[float, float, float] | None] = (), line_labels: Sequence[str | None] = (), scatter_color: Tuple[float, float, float] = (0, 0, 0), scatter_size: float = 2, title: str | None = '{frame_number}', vertical_axis: Literal['x', 'y', 'z'] = 'z', ticks_scale: float | None = None, azimuth: float = 20, elevation: float = 15, roll: float = 0, azimuth_delta: float = 0, elevation_delta: float = 0, roll_delta: float = 0, invert_x: bool = False, invert_y: bool = False, invert_z: bool = False, show_grid: bool = True, show_axis: bool = True, figure_scale: float | None = None, style: Literal['dark_background', 'default'] = 'default', layout: Literal['constrained', 'compressed', 'tight', 'none'] = 'none', interval: float | int = 37, repeat_delay: float | int = 100, blit: bool = True) FuncAnimation[source][source]
Animates the given frames representing 3D coordinates with 3D scatter plot and lines connecting those points.
- Parameters:
frames (Union[Sequence[Sequence[Tuple[float, float, float]]], NDArray]) – The frames to animate, represented as a sequence of collection of 3D coordinates.
line_indexes (Optional[Sequence[Sequence[int]]]) – The indexes of the points in a frame to connect in lines. If not provided, connects the points in a cycle [0, 1, 2, …, n-1, 0].
line_colors (Sequence[Union[Tuple[float, float, float], None]]) – The colors of the lines in RGB format normalized to [0.0, 1.0] range. If not provided, default to a gradient of blue to pink to blue.
line_labels (Sequence[Union[str, None]]) – The labels of the lines.
scatter_color (Tuple[float, float, float]) – The color of the scatter points in RGB format normalized to [0.0, 1.0] range. Default is black.
title (Optional[str]) – The title of the animation. Can include the placeholder “{frame_number}” to display the frame number. Defaults to “{frame_number}”.
vertical_axis (Literal["x", "y", "z"]) – The vertical axis in the plot. Default is “z”.
ticks_scale (Optional[float]) – The scale of the ticks. Defaults to the nearest power of 10 under the range in data.
layout (Literal["constrained", "compressed", "tight", "none"]) – The layout of the plot. Default is “none”.
interval (Union[float, int]) – The interval between frames in milliseconds. Default is 37.
repeat_delay (Union[float, int]) – The delay between replays in milliseconds. Default is 100.
blit (bool) – Whether to use blitting for faster updates. Default is True.
- Returns:
The animation object.
- Return type:
FuncAnimation
- classmethod frames_grid(frames: Sequence[Sequence[Tuple[float, float, float]]] | ndarray[Any, dtype[_ScalarType_co]], subplots: Tuple[int, int], line_indexes: Sequence[Sequence[int]] | None = None, line_colors: Sequence[Tuple[float, float, float] | None] = (), line_labels: Sequence[str | None] = (), scatter_color: Tuple[float, float, float] = (0, 0, 0), scatter_size: float = 2, title: str | None = '{frame_number}', figure_title: str | None = None, figure_title_font_size: float = 20, vertical_axis: Literal['x', 'y', 'z'] = 'z', ticks_scale: float | None = None, azimuth: float = 20, elevation: float = 15, roll: float = 0, azimuth_delta: float = 0, elevation_delta: float = 0, roll_delta: float = 0, invert_x: bool = False, invert_y: bool = False, invert_z: bool = False, show_grid: bool = True, show_axis: bool = True, figure_scale: float | None = 4, style: Literal['dark_background', 'default'] = 'default', layout: Literal['constrained', 'compressed', 'tight', 'none'] = 'tight') Figure[source][source]
Generates a grid of frames with 3D scatter plots and lines connecting the points.
- Parameters:
frames (Union[Sequence[Sequence[Tuple[float, float, float]]], NDArray]) – The frames containing the 3D coordinates of the points.
subplots (Tuple[int, int]) – The number of rows and columns in the figure. Each cell is a 3D plot containing one frame.
line_indexes (Optional[Sequence[Sequence[int]]]) – The indexes of points to be connected with lines.
line_colors (Sequence[Union[Tuple[float, float, float], None]]) – The colors of the lines connecting the points. Color should be in RGB format and in range [0.0, 1.0].
line_labels (Sequence[Union[str, None]]) – The labels for the lines connecting the points.
scatter_color (Tuple[float, float, float]) – The color of the scatter points. Color should be in RGB format and in range [0.0, 1.0].
scatter_size (float) – The size of the scatter points.
title (Optional[str]) – The title of each subplot. Can include the placeholder “{frame_number}” to display the frame number.
figure_title (Optional[str]) – The title of the entire figure.
figure_title_font_size (float) – The font size of the figure title.
vertical_axis (Literal["x", "y", "z"]) – The vertical axis in the 3D plots.
azimuth (float) – The azimuth angle (rotation around the vertical axis) of the initial view in the plot. Value must be in degrees.
elevation (float) – The elevation angle (amount of rise from the horizontal plane) of the initial view in the plot. Value must be in degrees.
roll (float) – The roll angle (rotation around the line of sight) of the initial view in the plot. Value must be in degrees.
azimuth_delta (float) – The change in azimuth angle for each subplot. Value must be in degrees.
elevation_delta (float) – The change in elevation angle for each subplot. Value must be in degrees.
roll_delta (float) – The change in roll angle for each subplot. Value must be in degrees.
invert_x (bool) – Whether to invert the x-axis.
invert_y (bool) – Whether to invert the y-axis.
invert_z (bool) – Whether to invert the z-axis.
show_grid (bool) – Whether to show the grid lines on the axes.
show_axis (bool) – Whether to show the axis lines.
figure_scale (Optional[float]) – The size of the entire figure.
style (Literal["dark_background", "default"]) – The color theme of the plot.
layout (Literal["constrained", "compressed", "tight", "none"]) – The spacing between the subplots.
- Returns:
The generated matplotlib figure.
- Return type:
Figure
- static initialize_Axes3D(ax: Axes, x_limits: Tuple[float, float], y_limits: Tuple[float, float], z_limits: Tuple[float, float], ticks_scale: float = 1.0, azimuth: float = 20, elevation: float = 15, roll: float = 0, vertical_axis: str = 'y', invert_x: bool = False, invert_y: bool = False, invert_z: bool = False, show_grid: bool = True, show_axis: bool = True) None[source][source]
Initializes a 3D Axes object with specified limits, ticks, and settings.
- Parameters:
ax (Axes) – The 3D Axes object to be initialized.
x_limits (Tuple[float, float]) – The range of the x-axis from minimum to maximum value.
y_limits (Tuple[float, float]) – The range of the y-axis from minimum to maximum value.
z_limits (Tuple[float, float]) – The range of the z-axis from minimum to maximum value.
- static new_figure(x_limits: Tuple[float, float], y_limits: Tuple[float, float], z_limits: Tuple[float, float], vertical_axis: Literal['x', 'y', 'z'] = 'z', figure_scale: float | None = 5, style: Literal['dark_background', 'default'] = 'default', layout: Literal['constrained', 'compressed', 'tight', 'none'] = 'compressed', subplots: Tuple[int, int] = (1, 1)) Tuple[Figure, List[Axes]][source][source]
Creates a new 3D figure with the specified subplots and settings.
- static placeholder_scatter_and_lines(ax: Axes, n_lines: int, line_colors: Sequence[Tuple[float, float, float] | None] = (), line_labels: Sequence[str | None] = (), scatter_color: Tuple[float, float, float] = (0, 0, 0), scatter_size: float = 2) Tuple[Path3DCollection, List[Line3D]][source][source]
Update a 3D plot with empty Path3DCollection (scatter) and Line3D objects.
- Parameters:
ax (Axes) – The 3D axes object to plot on.
n_lines (int) – The number of placeholder lines to create.
line_colors (Sequence[Union[Tuple[float, float, float], None]], optional) – The colors of the lines. If not provided, a gradient of colors will be used.
line_labels (Sequence[Union[str, None]], optional) – The labels for the lines.
scatter_color (Tuple[float, float, float], optional) – The RGB color of the scatter points normalized to [0.0, 1.0] range. Defaults to black.
scatter_size (float, optional) – The size of the scatter points. Defaults to 2.
- Returns:
A tuple containing the scatter plot and the list of lines.
- Return type:
Tuple[Path3DCollection, List[Line3D]]
- static set_frame_data(points: Sequence[Tuple[float, float, float]] | ndarray[Any, dtype[_ScalarType_co]], scatter: Path3DCollection, lines: Sequence[Line3D], line_indexes: Sequence[Sequence[int]] = (), ax: Axes | None = None, azimuth_delta: float = 0, elevation_delta: float = 0, roll_delta: float = 0) List[Path3DCollection | Line3D][source][source]
Sets the frame data for visualization.
- Parameters:
points (Union[Sequence[Tuple[float, float, float]], NDArray]) – A collection of tuples or a 2D NDArray representing the (x, y, z) points.
scatter (Path3DCollection) – Object representing the scatter plot.
lines (Sequence[Line3D]) – A sequence of Line3D objects representing the lines to be plotted.
line_indexes (Sequence[Sequence[int]], optional) – indexes of points to connect with lines. Defaults to ().
ax (Optional[Axes], optional) – An optional Axes object to update the view. Defaults to None.
- Returns:
A list containing the updated scatter plot and lines objects.
- Return type:
List[Union[Path3DCollection, Line3D]]