sleap.io.visuals#

Module for generating videos with visual annotation overlays.

class sleap.io.visuals.VideoMarkerThread(in_q: Queue, out_q: Queue, labels: Labels, video_idx: int, scale: float, show_edges: bool = True, edge_is_wedge: bool = False, marker_size: int = 4, crop_size_xy: Tuple[int, int] | None = None, color_manager: ColorManager | None = None, palette: str = 'standard', distinctly_color: str = 'instances')[source]#

Annotate frame images (draw instances).

Parameters:
  • in_q – Queue with (list of frame indexes, ndarray of frame images).

  • out_q – Queue to send annotated images as (images, h, w, channels) ndarray.

  • labels – the Labels object from which to get data for annotating.

  • video_idx – index of Video in labels.videos list.

  • scale – scale of image (so we can scale point locations to match)

  • show_edges – whether to draw lines between nodes

  • color_manager – ColorManager object which determine what colors to use for what instance/node/edge

run()[source]#

Method representing the thread’s activity.

You may override this method in a subclass. The standard run() method invokes the callable object passed to the object’s constructor as the target argument, if any, with sequential and keyword arguments taken from the args and kwargs arguments, respectively.

sleap.io.visuals.img_to_cv(img: ndarray) ndarray[source]#

Prepares frame image as needed for opencv.

sleap.io.visuals.reader(out_q: Queue, video: Video, frames: List[int], scale: float = 1.0, background: str = 'original')[source]#

Read frame images from video and send them into queue.

Parameters:
  • out_q – Queue to send (list of frame indexes, ndarray of frame images) for chunks of video.

  • video – The Video object to read.

  • frames – Full list frame indexes we want to read.

  • scale – Output scale for frame images.

  • background – output video background. Either original, black, white, grey

Returns:

None.

sleap.io.visuals.resize_image(img: ndarray, scale: float) ndarray[source]#

Resizes single image with shape (height, width, channels).

sleap.io.visuals.save_labeled_video(filename: str, labels: Labels, video: Video, frames: List[int], fps: int = 15, scale: float = 1.0, crop_size_xy: Tuple[int, int] | None = None, background: str = 'original', show_edges: bool = True, edge_is_wedge: bool = False, marker_size: int = 4, color_manager: ColorManager | None = None, palette: str = 'standard', distinctly_color: str = 'instances', gui_progress: bool = False)[source]#

Function to generate and save video with annotations.

Parameters:
  • filename – Output filename.

  • labels – The dataset from which to get data.

  • video – The source Video we want to annotate.

  • frames – List of frames to include in output video.

  • fps – Frames per second for output video.

  • scale – scale of image (so we can scale point locations to match)

  • crop_size_xy – size of crop around instances, or None for full images

  • background – output video background. Either original, black, white, grey

  • show_edges – whether to draw lines between nodes

  • edge_is_wedge – whether to draw edges as wedges (draw as line if False)

  • marker_size – Size of marker in pixels before scaling by scale

  • color_manager – ColorManager object which determine what colors to use for what instance/node/edge

  • palette – SLEAP color palette to use. Options include: “alphabet”, “five+”, “solarized”, or “standard”. Only used if color_manager is None.

  • distinctly_color – Specify how to color instances. Options include: “instances”, “edges”, and “nodes”. Only used if color_manager is None.

  • gui_progress – Whether to show Qt GUI progress dialog.

Returns:

None.

sleap.io.visuals.writer(in_q: Queue, progress_queue: Queue, filename: str, fps: float)[source]#

Write annotated images to video.

Image size is determined by the first image received in queue.

Parameters:
  • in_q – Queue with annotated images as (images, h, w, channels) ndarray

  • progress_queue – Queue to send progress as (total frames written: int, elapsed time: float). Send (-1, elapsed time) when done.

  • filename – full path to output video

  • fps – frames per second for output video

Returns:

None.