poseinterface.io.annotations_to_poseinterface#

poseinterface.io.annotations_to_poseinterface(input_path, output_dir, *, sub_id, ses_id, cam_id, format='frame')[source]#

Export annotations file from a single video to poseinterface format.

Parameters:
  • input_path (Path) – Path to the input annotations file.

  • output_dir (Path) – Directory where the output poseinterface COCO JSON file will be saved.

  • sub_id (str) – Subject ID to include in the generated filenames.

  • ses_id (str) – Session ID to include in the generated filenames.

  • cam_id (str) – Camera ID to include in the generated filenames.

  • format (Literal['clip', 'frame']) – Whether to generate frame labels or clip labels. Default is “frame”.

Returns:

Path to the saved poseinterface COCO JSON file.

Return type:

Path

Raises:

ValueError – If no labeled frames could be extracted from the input file, or if the annotations refer to multiple videos.

Notes

The format of the input annotations file is automatically inferred based on its extension. See sleap_io.io.main.load_file() for supported formats.

See also

sleap_io.io.main.load_file

The underlying function used to load the input annotations file as a SLEAP labels object.

sleap_io.io.coco.convert_labels

The underlying function used to convert SLEAP labels to COCO format.

Example

>>> from pathlib import Path
>>> from poseinterface.io import annotations_to_poseinterface
>>> coco_json_path = annotations_to_poseinterface(
...     input_path=Path("path/to/annotations.slp"),
...     output_dir=Path("path/to/output_directory"),
...     sub_id="testSub123",
...     ses_id="testSes123",
...     cam_id="testCam123",
... )