callbacks
sleap_io.rendering.callbacks
¶
Callback context classes for custom rendering.
This module provides context objects that are passed to user-defined callbacks during rendering, giving access to the Skia canvas and rendering metadata.
Classes:
| Name | Description |
|---|---|
InstanceContext |
Context passed to per-instance callbacks. |
RenderContext |
Context passed to pre/post render callbacks. |
Attributes:
| Name | Type | Description |
|---|---|---|
TYPE_CHECKING |
Returns True when the argument is true, False otherwise. |
|
__cached__ |
str(object='') -> str |
|
__doc__ |
str(object='') -> str |
|
__file__ |
str(object='') -> str |
|
__name__ |
str(object='') -> str |
|
__package__ |
str(object='') -> str |
TYPE_CHECKING = False
module-attribute
¶
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
__cached__ = '/home/runner/work/sleap-io/sleap-io/sleap_io/rendering/__pycache__/callbacks.cpython-313.pyc'
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__doc__ = 'Callback context classes for custom rendering.\n\nThis module provides context objects that are passed to user-defined callbacks\nduring rendering, giving access to the Skia canvas and rendering metadata.\n'
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__file__ = '/home/runner/work/sleap-io/sleap-io/sleap_io/rendering/callbacks.py'
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__name__ = 'sleap_io.rendering.callbacks'
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__package__ = 'sleap_io.rendering'
module-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
InstanceContext
¶
Context passed to per-instance callbacks.
This context provides access to the Skia canvas and instance-level metadata for drawing custom overlays after each instance is rendered.
Attributes:
| Name | Type | Description |
|---|---|---|
canvas |
Skia canvas for drawing. |
|
instance_idx |
Index of this instance within the frame. |
|
points |
(n_nodes, 2) array of keypoint coordinates. |
|
track_id |
Track ID if assigned, else None. |
|
track_name |
Track name string if available. |
|
confidence |
Instance confidence score if available. |
|
skeleton_edges |
Edge connectivity as list of (src, dst) tuples. |
|
node_names |
List of node name strings. |
|
scale |
Current scale factor for rendering. |
|
offset |
Current offset (x, y) for cropped/zoomed views. |
Methods:
| Name | Description |
|---|---|
__eq__ |
Method generated by attrs for class InstanceContext. |
__init__ |
Method generated by attrs for class InstanceContext. |
__repr__ |
Method generated by attrs for class InstanceContext. |
get_bbox |
Get bounding box of valid points. |
get_centroid |
Get centroid of valid points. |
world_to_canvas |
Transform world coordinates to canvas coordinates. |
Source code in sleap_io/rendering/callbacks.py
@define
class InstanceContext:
"""Context passed to per-instance callbacks.
This context provides access to the Skia canvas and instance-level metadata
for drawing custom overlays after each instance is rendered.
Attributes:
canvas: Skia canvas for drawing.
instance_idx: Index of this instance within the frame.
points: (n_nodes, 2) array of keypoint coordinates.
track_id: Track ID if assigned, else None.
track_name: Track name string if available.
confidence: Instance confidence score if available.
skeleton_edges: Edge connectivity as list of (src, dst) tuples.
node_names: List of node name strings.
scale: Current scale factor for rendering.
offset: Current offset (x, y) for cropped/zoomed views.
"""
canvas: "skia.Canvas"
instance_idx: int
points: np.ndarray
skeleton_edges: list[tuple[int, int]]
node_names: list[str]
track_id: int | None = None
track_name: str | None = None
confidence: float | None = None
scale: float = 1.0
offset: tuple[float, float] = (0.0, 0.0)
def world_to_canvas(self, x: float, y: float) -> tuple[float, float]:
"""Transform world coordinates to canvas coordinates.
Args:
x: X coordinate in world/frame space.
y: Y coordinate in world/frame space.
Returns:
(x, y) coordinates in canvas space.
"""
return (
(x - self.offset[0]) * self.scale,
(y - self.offset[1]) * self.scale,
)
def get_centroid(self) -> tuple[float, float] | None:
"""Get centroid of valid points.
Returns:
(x, y) mean of valid (non-NaN) points, or None if all invalid.
"""
valid_mask = np.isfinite(self.points).all(axis=1)
valid_points = self.points[valid_mask]
if len(valid_points) == 0:
return None
mean_pt = valid_points.mean(axis=0)
return (float(mean_pt[0]), float(mean_pt[1]))
def get_bbox(self) -> tuple[float, float, float, float] | None:
"""Get bounding box of valid points.
Returns:
(x1, y1, x2, y2) bounding box, or None if no valid points.
"""
valid_mask = np.isfinite(self.points).all(axis=1)
valid_points = self.points[valid_mask]
if len(valid_points) == 0:
return None
return (
float(valid_points[:, 0].min()),
float(valid_points[:, 1].min()),
float(valid_points[:, 0].max()),
float(valid_points[:, 1].max()),
)
__annotations__ = {'canvas': "'skia.Canvas'", 'instance_idx': 'int', 'points': 'np.ndarray', 'skeleton_edges': 'list[tuple[int, int]]', 'node_names': 'list[str]', 'track_id': 'int | None', 'track_name': 'str | None', 'confidence': 'float | None', 'scale': 'float', 'offset': 'tuple[float, float]'}
class-attribute
¶
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
__attrs_own_setattr__ = False
class-attribute
¶
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
__attrs_props__ = ClassProps(is_exception=False, is_slotted=True, has_weakref_slot=True, is_frozen=False, kw_only=<KeywordOnly.NO: 'no'>, collected_fields_by_mro=True, added_init=True, added_repr=True, added_eq=True, added_ordering=False, hashability=<Hashability.UNHASHABLE: 'unhashable'>, added_match_args=True, added_str=False, added_pickling=True, on_setattr_hook=<function pipe.<locals>.wrapped_pipe at 0x7f08471ce840>, field_transformer=None)
class-attribute
¶
Effective class properties as derived from parameters to attr.s() or
define() decorators.
This is the same data structure that attrs uses internally to decide how to construct the final class.
Warning:
This feature is currently **experimental** and is not covered by our
strict backwards-compatibility guarantees.
Attributes:
| Name | Type | Description |
|---|---|---|
is_exception |
bool
|
Whether the class is treated as an exception class. |
is_slotted |
bool
|
Whether the class is |
has_weakref_slot |
bool
|
Whether the class has a slot for weak references. |
is_frozen |
bool
|
Whether the class is frozen. |
kw_only |
KeywordOnly
|
Whether / how the class enforces keyword-only arguments on the
|
collected_fields_by_mro |
bool
|
Whether the class fields were collected by method resolution order.
That is, correctly but unlike |
added_init |
bool
|
Whether the class has an attrs-generated |
added_repr |
bool
|
Whether the class has an attrs-generated |
added_eq |
bool
|
Whether the class has attrs-generated equality methods. |
added_ordering |
bool
|
Whether the class has attrs-generated ordering methods. |
hashability |
Hashability
|
How |
added_match_args |
bool
|
Whether the class supports positional |
added_str |
bool
|
Whether the class has an attrs-generated |
added_pickling |
bool
|
Whether the class has attrs-generated |
on_setattr_hook |
Callable[[Any, Attribute[Any], Any], Any] | None
|
The class's |
field_transformer |
Callable[[Attribute[Any]], Attribute[Any]] | None
|
The class's |
.. versionadded:: 25.4.0
__doc__ = 'Context passed to per-instance callbacks.\n\nThis context provides access to the Skia canvas and instance-level metadata\nfor drawing custom overlays after each instance is rendered.\n\nAttributes:\n canvas: Skia canvas for drawing.\n instance_idx: Index of this instance within the frame.\n points: (n_nodes, 2) array of keypoint coordinates.\n track_id: Track ID if assigned, else None.\n track_name: Track name string if available.\n confidence: Instance confidence score if available.\n skeleton_edges: Edge connectivity as list of (src, dst) tuples.\n node_names: List of node name strings.\n scale: Current scale factor for rendering.\n offset: Current offset (x, y) for cropped/zoomed views.\n'
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__firstlineno__ = 61
class-attribute
¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral.
int('0b100', base=0) 4
__match_args__ = ('canvas', 'instance_idx', 'points', 'skeleton_edges', 'node_names', 'track_id', 'track_name', 'confidence', 'scale', 'offset')
class-attribute
¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__module__ = 'sleap_io.rendering.callbacks'
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__slots__ = ('canvas', 'instance_idx', 'points', 'skeleton_edges', 'node_names', 'track_id', 'track_name', 'confidence', 'scale', 'offset', '__weakref__')
class-attribute
¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__static_attributes__ = ()
class-attribute
¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__weakref__
property
¶
list of weak references to the object
__eq__(other)
¶
Method generated by attrs for class InstanceContext.
Source code in sleap_io/rendering/callbacks.py
@define
class RenderContext:
"""Context passed to pre/post render callbacks.
This context provides access to the Skia canvas and frame-level metadata
for drawing custom overlays before or after pose rendering.
Attributes:
canvas: Skia canvas for drawing.
frame_idx: Current frame index.
frame_size: (width, height) tuple of original frame dimensions.
instances: List of instances in this frame.
skeleton_edges: Edge connectivity as list of (src, dst) tuples.
__init__(canvas, instance_idx, points, skeleton_edges, node_names, track_id=None, track_name=None, confidence=None, scale=1.0, offset=(0.0, 0.0))
¶
Method generated by attrs for class InstanceContext.
Source code in sleap_io/rendering/callbacks.py
__repr__()
¶
Method generated by attrs for class InstanceContext.
Source code in sleap_io/rendering/callbacks.py
"""Callback context classes for custom rendering.
This module provides context objects that are passed to user-defined callbacks
during rendering, giving access to the Skia canvas and rendering metadata.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
import numpy as np
from attrs import define
if TYPE_CHECKING:
import skia
get_bbox()
¶
Get bounding box of valid points.
Returns:
| Type | Description |
|---|---|
tuple[float, float, float, float] | None
|
(x1, y1, x2, y2) bounding box, or None if no valid points. |
Source code in sleap_io/rendering/callbacks.py
def get_bbox(self) -> tuple[float, float, float, float] | None:
"""Get bounding box of valid points.
Returns:
(x1, y1, x2, y2) bounding box, or None if no valid points.
"""
valid_mask = np.isfinite(self.points).all(axis=1)
valid_points = self.points[valid_mask]
if len(valid_points) == 0:
return None
return (
float(valid_points[:, 0].min()),
float(valid_points[:, 1].min()),
float(valid_points[:, 0].max()),
float(valid_points[:, 1].max()),
)
get_centroid()
¶
Get centroid of valid points.
Returns:
| Type | Description |
|---|---|
tuple[float, float] | None
|
(x, y) mean of valid (non-NaN) points, or None if all invalid. |
Source code in sleap_io/rendering/callbacks.py
def get_centroid(self) -> tuple[float, float] | None:
"""Get centroid of valid points.
Returns:
(x, y) mean of valid (non-NaN) points, or None if all invalid.
"""
valid_mask = np.isfinite(self.points).all(axis=1)
valid_points = self.points[valid_mask]
if len(valid_points) == 0:
return None
mean_pt = valid_points.mean(axis=0)
return (float(mean_pt[0]), float(mean_pt[1]))
world_to_canvas(x, y)
¶
Transform world coordinates to canvas coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
X coordinate in world/frame space. |
required |
y
|
float
|
Y coordinate in world/frame space. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
(x, y) coordinates in canvas space. |
Source code in sleap_io/rendering/callbacks.py
def world_to_canvas(self, x: float, y: float) -> tuple[float, float]:
"""Transform world coordinates to canvas coordinates.
Args:
x: X coordinate in world/frame space.
y: Y coordinate in world/frame space.
Returns:
(x, y) coordinates in canvas space.
"""
return (
(x - self.offset[0]) * self.scale,
(y - self.offset[1]) * self.scale,
)
RenderContext
¶
Context passed to pre/post render callbacks.
This context provides access to the Skia canvas and frame-level metadata for drawing custom overlays before or after pose rendering.
Attributes:
| Name | Type | Description |
|---|---|---|
canvas |
Skia canvas for drawing. |
|
frame_idx |
Current frame index. |
|
frame_size |
(width, height) tuple of original frame dimensions. |
|
instances |
List of instances in this frame. |
|
skeleton_edges |
Edge connectivity as list of (src, dst) tuples. |
|
node_names |
List of node name strings. |
|
scale |
Current scale factor for rendering. |
|
offset |
Current offset (x, y) for cropped/zoomed views. |
Methods:
| Name | Description |
|---|---|
__eq__ |
Method generated by attrs for class RenderContext. |
__init__ |
Method generated by attrs for class RenderContext. |
__repr__ |
Method generated by attrs for class RenderContext. |
world_to_canvas |
Transform world coordinates to canvas coordinates. |
Source code in sleap_io/rendering/callbacks.py
@define
class RenderContext:
"""Context passed to pre/post render callbacks.
This context provides access to the Skia canvas and frame-level metadata
for drawing custom overlays before or after pose rendering.
Attributes:
canvas: Skia canvas for drawing.
frame_idx: Current frame index.
frame_size: (width, height) tuple of original frame dimensions.
instances: List of instances in this frame.
skeleton_edges: Edge connectivity as list of (src, dst) tuples.
node_names: List of node name strings.
scale: Current scale factor for rendering.
offset: Current offset (x, y) for cropped/zoomed views.
"""
canvas: "skia.Canvas"
frame_idx: int
frame_size: tuple[int, int]
instances: list
skeleton_edges: list[tuple[int, int]]
node_names: list[str]
scale: float = 1.0
offset: tuple[float, float] = (0.0, 0.0)
def world_to_canvas(self, x: float, y: float) -> tuple[float, float]:
"""Transform world coordinates to canvas coordinates.
Args:
x: X coordinate in world/frame space.
y: Y coordinate in world/frame space.
Returns:
(x, y) coordinates in canvas space.
"""
return (
(x - self.offset[0]) * self.scale,
(y - self.offset[1]) * self.scale,
)
__annotations__ = {'canvas': "'skia.Canvas'", 'frame_idx': 'int', 'frame_size': 'tuple[int, int]', 'instances': 'list', 'skeleton_edges': 'list[tuple[int, int]]', 'node_names': 'list[str]', 'scale': 'float', 'offset': 'tuple[float, float]'}
class-attribute
¶
dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2)
__attrs_own_setattr__ = False
class-attribute
¶
Returns True when the argument is true, False otherwise. The builtins True and False are the only two instances of the class bool. The class bool is a subclass of the class int, and cannot be subclassed.
__attrs_props__ = ClassProps(is_exception=False, is_slotted=True, has_weakref_slot=True, is_frozen=False, kw_only=<KeywordOnly.NO: 'no'>, collected_fields_by_mro=True, added_init=True, added_repr=True, added_eq=True, added_ordering=False, hashability=<Hashability.UNHASHABLE: 'unhashable'>, added_match_args=True, added_str=False, added_pickling=True, on_setattr_hook=<function pipe.<locals>.wrapped_pipe at 0x7f08471ce840>, field_transformer=None)
class-attribute
¶
Effective class properties as derived from parameters to attr.s() or
define() decorators.
This is the same data structure that attrs uses internally to decide how to construct the final class.
Warning:
This feature is currently **experimental** and is not covered by our
strict backwards-compatibility guarantees.
Attributes:
| Name | Type | Description |
|---|---|---|
is_exception |
bool
|
Whether the class is treated as an exception class. |
is_slotted |
bool
|
Whether the class is |
has_weakref_slot |
bool
|
Whether the class has a slot for weak references. |
is_frozen |
bool
|
Whether the class is frozen. |
kw_only |
KeywordOnly
|
Whether / how the class enforces keyword-only arguments on the
|
collected_fields_by_mro |
bool
|
Whether the class fields were collected by method resolution order.
That is, correctly but unlike |
added_init |
bool
|
Whether the class has an attrs-generated |
added_repr |
bool
|
Whether the class has an attrs-generated |
added_eq |
bool
|
Whether the class has attrs-generated equality methods. |
added_ordering |
bool
|
Whether the class has attrs-generated ordering methods. |
hashability |
Hashability
|
How |
added_match_args |
bool
|
Whether the class supports positional |
added_str |
bool
|
Whether the class has an attrs-generated |
added_pickling |
bool
|
Whether the class has attrs-generated |
on_setattr_hook |
Callable[[Any, Attribute[Any], Any], Any] | None
|
The class's |
field_transformer |
Callable[[Attribute[Any]], Attribute[Any]] | None
|
The class's |
.. versionadded:: 25.4.0
__doc__ = 'Context passed to pre/post render callbacks.\n\nThis context provides access to the Skia canvas and frame-level metadata\nfor drawing custom overlays before or after pose rendering.\n\nAttributes:\n canvas: Skia canvas for drawing.\n frame_idx: Current frame index.\n frame_size: (width, height) tuple of original frame dimensions.\n instances: List of instances in this frame.\n skeleton_edges: Edge connectivity as list of (src, dst) tuples.\n node_names: List of node name strings.\n scale: Current scale factor for rendering.\n offset: Current offset (x, y) for cropped/zoomed views.\n'
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__firstlineno__ = 18
class-attribute
¶
int([x]) -> integer int(x, base=10) -> integer
Convert a number or string to an integer, or return 0 if no arguments are given. If x is a number, return x.int(). For floating-point numbers, this truncates towards zero.
If x is not a number or if base is given, then x must be a string, bytes, or bytearray instance representing an integer literal in the given base. The literal can be preceded by '+' or '-' and be surrounded by whitespace. The base defaults to 10. Valid bases are 0 and 2-36. Base 0 means to interpret the base from the string as an integer iteral.
int('0b100', base=0) 4
__match_args__ = ('canvas', 'frame_idx', 'frame_size', 'instances', 'skeleton_edges', 'node_names', 'scale', 'offset')
class-attribute
¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__module__ = 'sleap_io.rendering.callbacks'
class-attribute
¶
str(object='') -> str str(bytes_or_buffer[, encoding[, errors]]) -> str
Create a new string object from the given object. If encoding or errors is specified, then the object must expose a data buffer that will be decoded using the given encoding and error handler. Otherwise, returns the result of object.str() (if defined) or repr(object). encoding defaults to 'utf-8'. errors defaults to 'strict'.
__slots__ = ('canvas', 'frame_idx', 'frame_size', 'instances', 'skeleton_edges', 'node_names', 'scale', 'offset', '__weakref__')
class-attribute
¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__static_attributes__ = ()
class-attribute
¶
Built-in immutable sequence.
If no argument is given, the constructor returns an empty tuple. If iterable is specified the tuple is initialized from iterable's items.
If the argument is a tuple, the return value is the same object.
__weakref__
property
¶
list of weak references to the object
__eq__(other)
¶
Method generated by attrs for class RenderContext.
Source code in sleap_io/rendering/callbacks.py
@define
class RenderContext:
"""Context passed to pre/post render callbacks.
This context provides access to the Skia canvas and frame-level metadata
for drawing custom overlays before or after pose rendering.
Attributes:
canvas: Skia canvas for drawing.
frame_idx: Current frame index.
frame_size: (width, height) tuple of original frame dimensions.
__init__(canvas, frame_idx, frame_size, instances, skeleton_edges, node_names, scale=1.0, offset=(0.0, 0.0))
¶
Method generated by attrs for class RenderContext.
Source code in sleap_io/rendering/callbacks.py
__repr__()
¶
Method generated by attrs for class RenderContext.
Source code in sleap_io/rendering/callbacks.py
"""Callback context classes for custom rendering.
This module provides context objects that are passed to user-defined callbacks
during rendering, giving access to the Skia canvas and rendering metadata.
"""
from __future__ import annotations
from typing import TYPE_CHECKING
import numpy as np
from attrs import define
if TYPE_CHECKING:
import skia
world_to_canvas(x, y)
¶
Transform world coordinates to canvas coordinates.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
x
|
float
|
X coordinate in world/frame space. |
required |
y
|
float
|
Y coordinate in world/frame space. |
required |
Returns:
| Type | Description |
|---|---|
tuple[float, float]
|
(x, y) coordinates in canvas space. |
Source code in sleap_io/rendering/callbacks.py
def world_to_canvas(self, x: float, y: float) -> tuple[float, float]:
"""Transform world coordinates to canvas coordinates.
Args:
x: X coordinate in world/frame space.
y: Y coordinate in world/frame space.
Returns:
(x, y) coordinates in canvas space.
"""
return (
(x - self.offset[0]) * self.scale,
(y - self.offset[1]) * self.scale,
)