PointcloudEpisodeAnnotation

class PointcloudEpisodeAnnotation(frames_count=None, objects=None, frames=None, tags=None, description='', key=None)[source]

Bases: object

Annotation for a point cloud episode (a sequence of frames) in Supervisely format.

Stores episode-level objects, per-frame data and tags, and supports JSON (de)serialization via to_json() / from_json().

PointcloudEpisodeAnnotation for point cloud episodes. PointcloudEpisodeAnnotation object is immutable.

Parameters:
frames_count : int

Number of pointcloud episode frames.

objects=None

Pointcloud episode objects collection.

frames=None

Pointcloud episode frames collection.

tags=None

Pointcloud episode tags collection.

description : str

Description text

key : uuid.UUID

UUID object.

Usage Example:
import supervisely as sly
from supervisely.video_annotation.key_id_map import KeyIdMap

# PointcloudEpisodeAnnotation example 1
pointcloud_episodes_ann = sly.PointcloudEpisodeAnnotation()
print(pointcloud_episodes_ann.to_json())
# Output: {
#     "description": "",
#     "frames": [],
#     "framesCount": None,
#     "key": "494f67984d714c1eaf7a65e5df289ac6",
#     "objects": [],
#     "tags": []
# }

# PointcloudEpisodeAnnotation example 2
pointcloud_id = 19481098
key_id_map = KeyIdMap()
pcd_info = api.pointcloud_episode.get_info_by_id(pointcloud_id)
project_meta_json = api.project.get_meta(pcd_info.project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)
ann_json = api.pointcloud_episode.annotation.download(pcd_info.dataset_id)
ann = sly.PointcloudEpisodeAnnotation.from_json(
    data=ann_json,
    project_meta=project_meta,
    key_id_map=key_id_map
)

Methods

clone

Makes a copy of PointcloudEpisodeAnnotation with new fields, if fields are given, otherwise it will use fields of the original PointcloudEpisodeAnnotation.

from_json

Create a PointcloudEpisodeAnnotation object from a JSON representation.

get_figures_on_frame

Retrieve figures associated with a specific frame in a PointcloudEpisodeAnnotation.

get_objects_on_frame

Retrieve objects associated with a specific frame in a PointcloudEpisodeAnnotation.

get_tags_on_frame

Retrieve tags associated with a specific frame in a PointcloudEpisodeAnnotation.

is_empty

Check whether pointcloud episode annotation contains objects or tags, or not.

key

PointcloudEpisodeAnnotation key value.

load_json_file

Loads json file and converts it to PointcloudEpisodeAnnotation.

to_json

Convert PointcloudEpisodeAnnotation to JSON format.

Attributes

description

Description text for PointcloudEpisodeAnnotation object.

figures

PointcloudFigure objects.

frames

PointcloudEpisodeFrameCollection collection.

frames_count

Number of frames.

objects

PointcloudEpisodeObject objects collection.

tags

PointcloudEpisodeTag objects collection.

classmethod from_json(data, project_meta, key_id_map=None)[source]

Create a PointcloudEpisodeAnnotation object from a JSON representation.

Parameters:
data : Dict

JSON data representing the PointcloudEpisodeAnnotation.

project_meta

Project metadata.

Returns:

Pointcloud episode annotation object.

Return type:

PointcloudEpisodeAnnotation

Usage Example:
import supervisely as sly
from supervisely.video_annotation.key_id_map import KeyIdMap

key_id_map = KeyIdMap()
pointcloud_id = 19481098
pcd_info = api.pointcloud_episode.get_info_by_id(pointcloud_id)
project_meta_json = api.project.get_meta(pcd_info.project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)
ann_json = api.pointcloud_episode.annotation.download(pcd_info.dataset_id)

ann = sly.PointcloudEpisodeAnnotation.from_json(
    data=ann_json,
    project_meta=project_meta,
    key_id_map=key_id_map
)
classmethod load_json_file(path, project_meta, key_id_map=None)[source]

Loads json file and converts it to PointcloudEpisodeAnnotation.

Parameters:
path : str

Path to the json file.

project_meta

Input project metadata.

key_id_map=None

Key ID map.

Returns:

Pointcloud episode annotation object.

Return type:

PointcloudEpisodeAnnotation

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

team_name = 'Vehicle Detection'
workspace_name = 'Cities'
project_name =  'London'

project_id = 19441
project_meta_json = api.project.get_meta(project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)

# Load json file
path = "/home/admin/work/docs/my_dataset/ann/annotation.json"
ann = sly.PointcloudEpisodeAnnotation.load_json_file(path, project_meta)
clone(frames_count=None, objects=None, frames=None, tags=None, description='')[source]

Makes a copy of PointcloudEpisodeAnnotation with new fields, if fields are given, otherwise it will use fields of the original PointcloudEpisodeAnnotation.

Parameters:
frames_count : int, optional

Number of pointcloud episode frames.

objects=None

Pointcloud episode objects collection.

frames=None

Pointcloud episode frames collection.

tags=None

Pointcloud episode tags collection.

description : str

Description text

Returns:

Pointcloud episode annotation object.

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly
from supervisely.video_annotation.key_id_map import KeyIdMap

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

key_id_map = KeyIdMap()
pointcloud_id = 19481098
pcd_info = api.pointcloud_episode.get_info_by_id(pointcloud_id)
project_meta_json = api.project.get_meta(pcd_info.project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)
ann_json = api.pointcloud_episode.annotation.download(pcd_info.dataset_id)
ann = sly.PointcloudAnnotation.from_json(
    data=ann_json,
    project_meta=project_meta,
    key_id_map=key_id_map
)

obj_class_car = sly.ObjClass('car', sly.Cuboid)
pointcloud_obj_car = sly.PointcloudEpisodeObject(obj_class_car)
new_objects = ann.objects.add(pointcloud_obj_car)

new_ann = ann.clone(objects=new_objects)
print(new_ann.to_json())
# Output:
# {
#     'datasetId': 60988,
#     'description': '',
#     'frames': [{'figures': [{'classId': None,
#                             'createdAt': '2023-03-16T06:38:45.004Z',
#                             'description': '',
#                             'geometry': {'dimensions': {'x': 2.3652234,
#                                                         'y': 23.291742,
#                                                         'z': 3.326648},
#                                         'position': {'x': 86.29707472161449,
#                                                         'y': -14.472597682830635,
#                                                         'z': 0.8842007608554671},
#                                         'rotation': {'x': 0,
#                                                         'y': 0,
#                                                         'z': -1.6962800995995606}},
#                             'geometryType': 'cuboid_3d',
#                             'id': 87536496,
#                             'labelerLogin': 'almaz',
#                             'objectId': 5531328,
#                             'updatedAt': '2023-03-16T06:38:45.004Z'}],
#                 'index': 0,
#                 'pointCloudId': 19481098}],
#                 'index': 1,
#                 'pointCloudId': 19481100},
#                 ...],
#     'framesCount': 54,
#     'objects': [{
#                     'classId': 666944,
#                     'classTitle': 'Car',
#                     'createdAt': '2023-03-16T06:38:44.934Z',
#                     'datasetId': 60988,
#                     'entityId': None,
#                     'id': 5531324,
#                     'labelerLogin': 'almaz',
#                     'tags': [],
#                     'updatedAt': '2023-03-16T06:38:44.934Z'}
#                 {
#                     'classTitle': 'Car',
#                     'createdAt': '2023-03-16T06:38:44.934Z',
#                     'key': 'fc149a8f3e3a413c807a6b4ba474645c',
#                     'labelerLogin': 'almaz',
#                     'tags': [],
#                     'updatedAt': '2023-03-16T06:38:44.934Z
#                 }],
#     'tags': []
# }
# Output: {
#     "description": "",
#     "figures": [],
#     "key": "2cc443272aca4cfa9c4f404614938aa7",
#     "objects": [
#         {
#         "classTitle": "Pole",
#         "createdAt": "2023-03-16T06:38:44.934Z",
#         "key": "eff2ec5e3cda47968f45bc51b36a0dc1",
#         "labelerLogin": "almaz",
#         "tags": [],
#         "updatedAt": "2023-03-16T06:38:44.934Z"
#         },
#         {
#         "classTitle": "Tram",
#         "createdAt": "2023-03-16T06:38:44.934Z",
#         "key": "6baa92e09ceb413ba8fbfcfae74be1c7",
#         "labelerLogin": "almaz",
#         "tags": [],
#         "updatedAt": "2023-03-16T06:38:44.934Z"
#         },
#         {
#         "classTitle": "car",
#         "key": "6b1bced23061437b8ddbcdd267548c96",
#         "tags": []
#         }
#     ],
#     "tags": []
# }
get_figures_on_frame(frame_index)[source]

Retrieve figures associated with a specific frame in a PointcloudEpisodeAnnotation.

Parameters:
frame_index : int

The index of the frame for which figures need to be retrieved.

Returns:

List of pointcloud figures containing the retrieved figures associated with the specified frame.

Return type:

List[PointcloudFigure]

Usage Example:
import supervisely as sly
from supervisely.video_annotation.key_id_map import KeyIdMap

key_id_map = KeyIdMap()
pointcloud_id = 19481098
pcd_info = api.pointcloud_episode.get_info_by_id(pointcloud_id)
project_meta_json = api.project.get_meta(pcd_info.project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)
ann_json = api.pointcloud_episode.annotation.download(pcd_info.dataset_id)
ann = sly.PointcloudEpisodeAnnotation.from_json(
    data=ann_json,
    project_meta=project_meta,
    key_id_map=key_id_map
)

frame_index = 0
figures_on_frame = ann.get_figures_on_frame(frame_index)
print(figures_on_frame)
# Output:
# [<supervisely.pointcloud_annotation.pointcloud_figure.PointcloudFigure object at 0x7fc83895a4d0>,
# <supervisely.pointcloud_annotation.pointcloud_figure.PointcloudFigure object at 0x7fc83895a810>,
# <supervisely.pointcloud_annotation.pointcloud_figure.PointcloudFigure object at 0x7fc8389410d0>]
get_objects_on_frame(frame_index)[source]

Retrieve objects associated with a specific frame in a PointcloudEpisodeAnnotation.

Parameters:
frame_index : int

The index of the frame for which objects need to be retrieved.

Returns:

PointcloudEpisodeObjectCollection containing the retrieved objects associated with the specified frame.

Return type:

Raises:

ValueError – If no frame with the given frame_index exists in the annotation.

Usage Example:
import supervisely as sly
from supervisely.video_annotation.key_id_map import KeyIdMap

key_id_map = KeyIdMap()
pointcloud_id = 19481098
pcd_info = api.pointcloud_episode.get_info_by_id(pointcloud_id)
project_meta_json = api.project.get_meta(pcd_info.project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)
ann_json = api.pointcloud_episode.annotation.download(pcd_info.dataset_id)
ann = sly.PointcloudEpisodeAnnotation.from_json(
    data=ann_json,
    project_meta=project_meta,
    key_id_map=key_id_map
)

frame_index = 0
objects_on_frame = ann.get_objects_on_frame(frame_index)
print(objects_on_frame.to_json())
# Output:
# [
#     {
#         "key": "687784c3d4d64ec4811948fec245514a",
#         "classTitle": "Tram",
#         "tags": [],
#         "labelerLogin": "almaz",
#         "updatedAt": "2023-03-16T06:38:44.934Z",
#         "createdAt": "2023-03-16T06:38:44.934Z"
#     },
#     {
#         "key": "b8b23b6712444f0fbfb320b0b4acd09a",
#         "classTitle": "Car",
#         "tags": [],
#         "labelerLogin": "almaz",
#         "updatedAt": "2023-03-16T06:38:44.934Z",
#         "createdAt": "2023-03-16T06:38:44.934Z"
#     }
# ]
get_tags_on_frame(frame_index)[source]

Retrieve tags associated with a specific frame in a PointcloudEpisodeAnnotation.

Parameters:
frame_index : int

The index of the frame for which tags need to be retrieved.

Returns:

PointcloudEpisodeTagCollection containing the retrieved tags associated with the specified frame.

Return type:

PointcloudEpisodeTagCollection

Raises:

ValueError – If no frame with the given frame_index exists in the annotation.

Usage Example:
import supervisely as sly
from supervisely.video_annotation.key_id_map import KeyIdMap

key_id_map = KeyIdMap()
pointcloud_id = 19481098
pcd_info = api.pointcloud_episode.get_info_by_id(pointcloud_id)
project_meta_json = api.project.get_meta(pcd_info.project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)
ann_json = api.pointcloud_episode.annotation.download(pcd_info.dataset_id)
ann = sly.PointcloudEpisodeAnnotation.from_json(
    data=ann_json,
    project_meta=project_meta,
    key_id_map=key_id_map
)
frame_index = 0
tags_on_frame = ann.get_tags_on_frame(frame_index)

print(tags_on_frame)
# Output:
Tags:
+-------+------------+-------+-------------+
|  Name | Value type | Value | Frame range |
+-------+------------+-------+-------------+
| color | any_string |  red  |   [0, 0]   |
+-------+------------+-------+-------------+
is_empty()[source]

Check whether pointcloud episode annotation contains objects or tags, or not.

Returns:

True if pointcloud episode annotation is empty, False otherwise.

Return type:

bool

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

project_id = 18428
dataset_id = 60988
key_id_map = KeyIdMap()
meta_json = api.project.get_meta(project_id)
meta = sly.ProjectMeta.from_json(meta_json)

ann_json = api.pointcloud_episode.annotation.download(dataset_id)
ann = sly.PointcloudEpisodeAnnotation.from_json(ann_json, meta, key_id_map)

print(ann.is_empty()) # False
key()[source]

PointcloudEpisodeAnnotation key value.

Returns:

Key value of pointcloud episode annotation object.

Return type:

str

Usage Example:
import supervisely as sly

ann = sly.PointcloudEpisodeAnnotation()
print(ann.key())
# Output: 93ab6292-c661-4a53-b407-85ed34f5b68a'
to_json(key_id_map=None)[source]

Convert PointcloudEpisodeAnnotation to JSON format.

Parameters:
key_id_map=None

Key ID map.

Returns:

PointcloudEpisodeAnnotation in JSON format.

Return type:

Dict

Usage Example:
import supervisely as sly

pointcloud_id = 19481098
pcd_info = api.pointcloud_episode.get_info_by_id(pointcloud_id)
project_path = "Downloads/pointcloud_api/project"
sly.PointcloudEpisodeProject.download(
    api=api,
    project_id=pcd_info.project_id,
    dest_dir=project_path,
    dataset_ids=[pcd_info.dataset_id],
    download_pointclouds=True,
)
project_fs = sly.PointcloudEpisodeProject(project_path, sly.OpenMode.READ)
project_meta_json = api.project.get_meta(pcd_info.project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)
ds = project_fs.datasets.items()[0]:
ann = ds.get_ann(project_meta)

print(ann.to_json())
# Output:
# {
#     'datasetId': 60988,
#     'description': '',
#     'frames': [{'figures': [{'classId': None,
#                             'createdAt': '2023-03-16T06:38:45.004Z',
#                             'description': '',
#                             'geometry': {'dimensions': {'x': 2.3652234,
#                                                         'y': 23.291742,
#                                                         'z': 3.326648},
#                                         'position': {'x': 86.29707472161449,
#                                                         'y': -14.472597682830635,
#                                                         'z': 0.8842007608554671},
#                                         'rotation': {'x': 0,
#                                                         'y': 0,
#                                                         'z': -1.6962800995995606}},
#                             'geometryType': 'cuboid_3d',
#                             'id': 87536496,
#                             'labelerLogin': 'almaz',
#                             'objectId': 5531328,
#                             'updatedAt': '2023-03-16T06:38:45.004Z'}],
#                 'index': 0,
#                 'pointCloudId': 19481098}],
#                 'index': 1,
#                 'pointCloudId': 19481100},
#                 ...],
#     'framesCount': 54,
#     'objects': [{'classId': 666944,
#                 'classTitle': 'Car',
#                 'createdAt': '2023-03-16T06:38:44.934Z',
#                 'datasetId': 60988,
#                 'entityId': None,
#                 'id': 5531324,
#                 'labelerLogin': 'almaz',
#                 'tags': [],
#                 'updatedAt': '2023-03-16T06:38:44.934Z'}],
#     'tags': []
# }
property description : str

Description text for PointcloudEpisodeAnnotation object.

Returns:

Pointcloud episode annotation description

Return type:

str

Usage Example:
import supervisely as sly

descr = 'example'
ann = sly.PointcloudEpisodeAnnotation(description=descr)
print(ann.description) # example
property figures : list[supervisely.pointcloud_annotation.pointcloud_figure.PointcloudFigure]

PointcloudFigure objects.

Returns:

List of pointcloud figures from PointcloudEpisodeAnnotation object.

Return type:

List[PointcloudFigure]

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

project_id = 19441
project_meta_json = api.project.get_meta(project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)

# Load json file
path = "/home/admin/work/docs/my_dataset/ann/annotation.json"
ann = sly.PointcloudEpisodeAnnotation.load_json_file(path, project_meta)

for figure in ann.figures:
    print(figure.to_json())

# Output:
# {
#     "geometry": {
#         "dimensions": { "x": 1.8, "y": 3.9, "z": 1.6 },
#         "position": { "x": -3.4, "y": 28.9, "z": -0.7 },
#         "rotation": { "x": 0.0, "y": 0, "z": -0.03 }
#     },
#     "geometryType": "cuboid_3d",
#     "key": "01836c294c514250a11889f56cf210e9",
#     "objectKey": "737c4df19c0c4cccbc48cf69b72abe36"
# }
property frames : supervisely.pointcloud_annotation.pointcloud_episode_frame_collection.PointcloudEpisodeFrameCollection

PointcloudEpisodeFrameCollection collection.

Returns:

Pointcloud episode frames collection.

Return type:

PointcloudEpisodeFrameCollection

Usage Example:
import supervisely as sly
from supervisely.geometry.cuboid_3d import Cuboid3d, Vector3d
from supervisely.pointcloud_annotation.pointcloud_episode_object_collection import PointcloudEpisodeObjectCollection

obj_class_car = sly.ObjClass('car', Cuboid3d)
pointcloud_obj_car = sly.PointcloudEpisodeObject(obj_class_car)
objects = sly.PointcloudEpisodeObjectCollection([pointcloud_obj_car])

position, rotation, dimension = Vector3d(-3.4, 28.9, -0.7), Vector3d(0., 0, -0.03), Vector3d(1.8, 3.9, 1.6)
cuboid = Cuboid3d(position, rotation, dimension)
frame_index = 10
figure = sly.PointcloudFigure(pointcloud_obj_car, cuboid, frame_index=frame_index)
frame = sly.PointcloudEpisodeFrame(frame_index, figures=[figure])
frames = sly.PointcloudEpisodeFrameCollection([frame])

pointcloud_episodes_ann = sly.PointcloudEpisodeAnnotation(frames_count, objects, frames)
print(pointcloud_episodes_ann.frames.to_json())
# Output:
# [
#     {
#         "figures": [
#         {
#             "geometry": {
#             "dimensions": { "x": 1.8, "y": 3.9, "z": 1.6 },
#             "position": { "x": -3.4, "y": 28.9, "z": -0.7 },
#             "rotation": { "x": 0.0, "y": 0, "z": -0.03 }
#             },
#             "geometryType": "cuboid_3d",
#             "key": "030b9aafa97642e887e2be544ef7a7ee",
#             "objectKey": "95c473a6cff44afda127ffb40d2bac5b"
#         }
#         ],
#         "index": 0
#     }
# ]
property frames_count : int

Number of frames.

Returns:

Frames count

Return type:

int

Usage Example:
import supervisely as sly

frames_count = 15
video_ann = sly.PointcloudEpisodeAnnotation(frames_count=frames_count)
print(video_ann.frames_count)
# Output: 15
property objects : supervisely.pointcloud_annotation.pointcloud_episode_object_collection.PointcloudEpisodeObjectCollection

PointcloudEpisodeObject objects collection.

Returns:

Pointcloud episode objects collection.

Return type:

PointcloudEpisodeObjectCollection

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

project_id = 19441
project_meta_json = api.project.get_meta(project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)

# Load json file
path = "/home/admin/work/docs/my_dataset/ann/annotation.json"
ann = sly.PointcloudEpisodeAnnotation.load_json_file(path, project_meta)

objects = ann.objects
property tags : supervisely.pointcloud_annotation.pointcloud_episode_tag_collection.PointcloudEpisodeTagCollection

PointcloudEpisodeTag objects collection.

Returns:

Pointcloud episode tags collection.

Return type:

PointcloudEpisodeTagCollection

Usage Example:
import os
from dotenv import load_dotenv

import supervisely as sly

# Load secrets and create API object from .env file (recommended)
# Learn more here: https://developer.supervisely.com/getting-started/basics-of-authentication
if sly.is_development():
    load_dotenv(os.path.expanduser("~/supervisely.env"))

api = sly.Api.from_env()

project_id = 19441
project_meta_json = api.project.get_meta(project_id)
project_meta = sly.ProjectMeta.from_json(project_meta_json)

# Load json file
path = "/home/admin/work/docs/my_dataset/ann/annotation.json"
ann = sly.PointcloudEpisodeAnnotation.load_json_file(path, project_meta)

tags = ann.tags