PointcloudFigureApi¶
- class PointcloudFigureApi[source]¶
Bases:
supervisely.api.entity_annotation.figure_api.FigureApi
PointcloudFigure
for a single point cloud.Methods
Add VideoFigures to given Video by ID.
Add pointcloud figures to Dataset annotations.
Create new PointcloudFigure of given point cloud object in point cloud with given ID.
Create figures in Supervisely in bulk.
Method returns a dictionary with pairs of pointcloud ID and list of FigureInfo for the given dataset ID.
Download figure geometries with given IDs from storage.
Download figure geometries with given IDs from storage asynchronously.
Download figure geometry with given ID from storage.
Checks if an entity with the given parent_id and name exists
Get Figures information by IDs from given dataset ID.
Generates a free name for an entity with the given parent_id and name.
Get Figure information by ID.
Get information about an entity by its name from the Supervisely server.
Get list of entities in parent entity with given parent ID.
Get list of all or limited quantity entities from the Supervisely server.
This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved
Get the list of items for a given page number.
Yields list of images in dataset asynchronously page by page.
NamedTuple FigureInfo information about Figure.
Get string name of NamedTuple for class.
Remove an entity with the specified ID from the Supervisely server.
Remove entities in batches from the Supervisely server.
Upload figure geometries with given figure IDs to storage.
Upload figure geometry with given figure ID to storage.
Attributes
MAX_WAIT_ATTEMPTS
Maximum number of attempts that will be made to wait for a certain condition to be met.
WAIT_ATTEMPT_TIMEOUT_SEC
Number of seconds for intervals between attempts.
- InfoType¶
alias of
supervisely.api.module_api.FigureInfo
- append_bulk(pointcloud_id, figures, key_id_map)[source]¶
Add VideoFigures to given Video by ID.
- Parameters
- pointcloud_id : int
Point cloud ID in Supervisely.
- figures : List[PointcloudFigure]
List of point cloud figures to append.
- key_id_map : KeyIdMap
KeyIdMap object.
- Returns
None
- Return type
NoneType
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() project_id = 124976 meta_json = api.project.get_meta(project_id) meta = sly.ProjectMeta.from_json(meta_json) key_id_map = KeyIdMap() pcd_id = 198703212 ann_info = api.pointcloud.annotation.download(pcd_id) ann = sly.PointcloudAnnotation.from_json(ann_info, meta, key_id_map) figures = ann.figures[:5] api.video.figure.append_bulk(pcd_id, figures, key_id_map)
- append_to_dataset(dataset_id, figures, entity_ids, key_id_map)[source]¶
Add pointcloud figures to Dataset annotations.
- Parameters
- dataset_id : int
Dataset
ID in Supervisely.- figures : List[PointcloudFigure]
List of point cloud figures.
- entity_ids : List[int]
List of point cloud IDs.
- key_id_map : KeyIdMap, optional
KeyIdMap object.
- Return type
NoneType
- Usage example
- Usage example
import supervisely as sly from supervisely.geometry.cuboid_3d import Cuboid3d, Vector3d from supervisely.pointcloud_annotation.pointcloud_annotation import PointcloudObjectCollection from supervisely.pointcloud_annotation.pointcloud_figure import PointcloudFigure from supervisely.video_annotation.key_id_map import KeyIdMap os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() project_id = 17231 dataset_id = 55875 pointcloud_id = 19373403 project = api.project.get_info_by_id(project_id) dataset = api.dataset.get_info_by_id(dataset_id) class_car = sly.ObjClass('car', Cuboid3d) classes = sly.ObjClassCollection([class_car]) project_meta = sly.ProjectMeta(classes) updated_meta = api.project.update_meta(project.id, project_meta.to_json()) key_id_map = KeyIdMap() car_object = sly.PointcloudObject(class_car) objects_collection = PointcloudObjectCollection([car_object]) uploaded_objects_ids = api.pointcloud_episode.object.append_to_dataset( dataset.id, objects_collection, key_id_map, ) position, rotation, dimension = Vector3d(-32.4, 33.9, -0.7), Vector3d(0., 0, 0.1), Vector3d(1.8, 3.9, 1.6) cuboid = Cuboid3d(position, rotation, dimension) figure_1 = PointcloudFigure(car_object, cuboid) api.pointcloud_episode.figure.append_to_dataset( dataset.id, [figure_1], [pointcloud_id], key_id_map, )
-
create(pointcloud_id, object_id, geometry_json, geometry_type, track_id=
None
)[source]¶ Create new PointcloudFigure of given point cloud object in point cloud with given ID.
- Parameters
- Returns
New figure ID
- Return type
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() pcd_id = 19618685 object_id = 5565921 geometry_json = {'points': {'exterior': [[500, 500], [1555, 1500]], 'interior': []}} geometry_type = 'rectangle' figure_id = api.pointcloud.figure.create(pcd_id, object_id, geometry_json, geometry_type) # 643182610
-
create_bulk(figures_json, entity_id=
None
, dataset_id=None
, batch_size=200
)¶ Create figures in Supervisely in bulk. To optimize creation of a large number of figures use dataset ID instead of entity ID. In this case figure jsons list can contain figures from different entities for the same dataset. Every figure json must contain corresponding entity ID.
NOTE: Geometries for AlphaMask must be uploaded separately via
upload_geometries_batch
method.
-
download(dataset_id, pointcloud_ids=
None
, skip_geometry=False
, **kwargs)[source]¶ Method returns a dictionary with pairs of pointcloud ID and list of FigureInfo for the given dataset ID. Can be filtered by pointcloud IDs.
- Parameters
- dataset_id : int
Dataset ID in Supervisely.
- pointcloud_ids : List[int], optional
Specify the list of pointcloud IDs within the given dataset ID. If pointcloud_ids is None, the method returns all possible pairs of images with figures. Note: Consider using
sly.batched()
to ensure that no figures are lost in the response.- skip_geometry : bool
Skip the download of figure geometry. May be useful for a significant api request speed increase in the large datasets.
- Returns
A dictionary where keys are pointcloud IDs and values are lists of figures.
- Return type
- class
Dict[int, List[FigureInfo]]
-
download_geometries_batch(ids, progress_cb=
None
)¶ Download figure geometries with given IDs from storage.
-
async download_geometries_batch_async(ids, progress_cb=
None
, semaphore=None
)¶ Download figure geometries with given IDs from storage asynchronously.
- Parameters
- ids : List[int]
List of figure IDs in Supervisely.
- progress_cb : Union[tqdm, Callable], optional
Progress bar to show the download progress. Shows the number of bytes downloaded.
- semaphore : Optional[asyncio.Semaphore], optional
Semaphore to limit the number of concurrent downloads.
- Returns
List of figure geometries in Supervisely JSON format.
- Return type
List[dict]
- Usage example
import asyncio import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() figure_ids = [642155547, 642155548, 642155549] loop = sly.utils.get_or_create_event_loop() geometries = loop.run_until_complete( api.figure.download_geometries_batch_async( figure_ids, progress_cb=tqdm(total=len(figure_ids), desc="Downloading geometries"), semaphore=asyncio.Semaphore(15), ) )
- download_geometry(figure_id)¶
Download figure geometry with given ID from storage.
- exists(parent_id, name)¶
Checks if an entity with the given parent_id and name exists
- Parameters
- Returns
Returns True if entity exists, and False if not
- Return type
- Usage example
import supervisely as sly # You can connect to API directly address = 'https://app.supervise.ly/' token = 'Your Supervisely API Token' api = sly.Api(address, token) # Or you can use API from environment os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() name = "IMG_0315.jpeg" dataset_id = 55832 exists = api.image.exists(dataset_id, name) print(exists) # True
- get_by_ids(dataset_id, ids)¶
Get Figures information by IDs from given dataset ID.
- Parameters
- Returns
List of information about Figures. See
info_sequence
- Return type
List[NamedTuple]
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() dataset_id = 466642 figures_ids = [642155547, 642155548, 642155549] figures_infos = api.video.figure.get_by_ids(dataset_id, figures_ids) print(figures_infos) # Output: [ # [ # 642155547, # "2021-03-23T13:25:34.705Z", # "2021-03-23T13:25:34.705Z", # 198703211, # 152118, # 124976, # 466642, # 0, # "rectangle", # { # "points": { # "exterior": [ # [ # 2240, # 1041 # ], # [ # 2463, # 1187 # ] # ], # "interior": [] # } # } # ], # [ # 642155548, # "2021-03-23T13:25:34.705Z", # "2021-03-23T13:25:34.705Z", # 198703211, # 152118, # 124976, # 466642, # 1, # "rectangle", # { # "points": { # "exterior": [ # [ # 2248, # 1048 # ], # [ # 2455, # 1176 # ] # ], # "interior": [] # } # } # ], # [ # 642155549, # "2021-03-23T13:25:34.705Z", # "2021-03-23T13:25:34.705Z", # 198703211, # 152118, # 124976, # 466642, # 2, # "rectangle", # { # "points": { # "exterior": [ # [ # 2237, # 1046 # ], # [ # 2464, # 1179 # ] # ], # "interior": [] # } # } # ] # ]
- get_free_name(parent_id, name)¶
Generates a free name for an entity with the given parent_id and name. Adds an increasing suffix to original name until a unique name is found.
- Parameters
- Returns
Returns free name.
- Return type
- Usage example
import supervisely as sly # You can connect to API directly address = 'https://app.supervise.ly/' token = 'Your Supervisely API Token' api = sly.Api(address, token) # Or you can use API from environment os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() name = "IMG_0315.jpeg" dataset_id = 55832 free_name = api.image.get_free_name(dataset_id, name) print(free_name) # IMG_0315_001.jpeg
- get_info_by_id(id)¶
Get Figure information by ID.
- Parameters
- id : int
Figure ID in Supervisely.
- Returns
Information about Figure. See
info_sequence
- Return type
NamedTuple
- Usage example
import supervisely as sly figure_id = 588801373 os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() figure_info = api.video.figure.get_info_by_id(figure_id) print(figure_info) # Output: [ # 588801373, # "2020-12-22T06:37:13.183Z", # "2020-12-22T06:37:13.183Z", # 186648101, # 112482, # 110366, # 419886, # 0, # "bitmap", # { # "bitmap": { # "data": "eJw...Cgj4=", # "origin": [ # 335, # 205 # ] # } # } # ]
-
get_info_by_name(parent_id, name, fields=
[]
)¶ Get information about an entity by its name from the Supervisely server.
- Parameters
- Usage example
import supervisely as sly # You can connect to API directly address = 'https://app.supervise.ly/' token = 'Your Supervisely API Token' api = sly.Api(address, token) # Or you can use API from environment os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() dataset_id = 55832 name = "IMG_0315.jpeg" info = api.image.get_info_by_name(dataset_id, name) print(info) # Output: ImageInfo(id=19369643, name='IMG_0315.jpeg', ...)
-
get_list(parent_id, filters=
None
)¶ Get list of entities in parent entity with given parent ID.
- Parameters
- Usage example
import supervisely as sly # You can connect to API directly address = 'https://app.supervise.ly/' token = 'Your Supervisely API Token' api = sly.Api(address, token) # Or you can use API from environment os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() dataset_id = 55832 images = api.image.get_list(dataset_id) print(images) # Output: [ ImageInfo(id=19369642, ...) ImageInfo(id=19369643, ...) ImageInfo(id=19369644, ...) ]
-
get_list_all_pages(method, data, progress_cb=
None
, convert_json_info_cb=None
, limit=None
, return_first_response=False
)¶ Get list of all or limited quantity entities from the Supervisely server.
- Parameters
- method : str
Request method name
- data : dict
Dictionary with request body info
- progress_cb : Progress, optional
Function for tracking download progress.
- convert_json_info_cb : Callable, optional
Function for convert json info
- limit : int, optional
Number of entity to retrieve
- return_first_response : bool, optional
Specify if return first response
-
get_list_all_pages_generator(method, data, progress_cb=
None
, convert_json_info_cb=None
, limit=None
, return_first_response=False
)¶ This generator function retrieves a list of all or a limited quantity of entities from the Supervisely server, yielding batches of entities as they are retrieved
- Parameters
- method : str
Request method name
- data : dict
Dictionary with request body info
- progress_cb : Progress, optional
Function for tracking download progress.
- convert_json_info_cb : Callable, optional
Function for convert json info
- limit : int, optional
Number of entity to retrieve
- return_first_response : bool, optional
Specify if return first response
- async get_list_idx_page_async(method, data)¶
Get the list of items for a given page number. Page number is specified in the data dictionary.
-
async get_list_page_generator_async(method, data, pages_count=
None
, semaphore=None
)¶ Yields list of images in dataset asynchronously page by page.
- Parameters
- method : str
Method to call for listing items.
- data : dict
Data to pass to the API method.
- pages_count : int, optional
Preferred number of pages to retrieve if used with a
per_page
limit. Will be automatically adjusted if thepagesCount
differs from the requested number.- semaphore :
asyncio.Semaphore
, optional Semaphore for limiting the number of simultaneous requests.
- kwargs
Additional arguments.
- Returns
List of images in dataset.
- Return type
AsyncGenerator[List[ImageInfo]]
- Usage example
import supervisely as sly import asyncio os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() method = 'images.list' data = { 'datasetId': 123456 } loop = sly.utils.get_or_create_event_loop() images = loop.run_until_complete(api.image.get_list_generator_async(method, data))
- static info_sequence()¶
NamedTuple FigureInfo information about Figure.
- Example
FigureInfo(id=588801373, updated_at='2020-12-22T06:37:13.183Z', created_at='2020-12-22T06:37:13.183Z', entity_id=186648101, object_id=112482, project_id=110366, dataset_id=419886, frame_index=0, geometry_type='bitmap', geometry={'bitmap': {'data': 'eJwdlns8...Cgj4=', 'origin': [335, 205]}})
- static info_tuple_name()¶
Get string name of NamedTuple for class.
- Returns
NamedTuple name.
- Return type
- Usage example
import supervisely as sly os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() tuple_name = api.video.figure.info_tuple_name() print(tuple_name) # FigureInfo
- remove(id)¶
Remove an entity with the specified ID from the Supervisely server.
- Parameters
- id : int
Entity ID in Supervisely.
- Usage example
import supervisely as sly # You can connect to API directly address = 'https://app.supervise.ly/' token = 'Your Supervisely API Token' api = sly.Api(address, token) # Or you can use API from environment os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() image_id = 19369643 api.image.remove(image_id)
-
remove_batch(ids, progress_cb=
None
, batch_size=50
)¶ Remove entities in batches from the Supervisely server. All entity IDs must belong to the same nesting (for example team, or workspace, or project, or dataset). Therefore, it is necessary to sort IDs before calling this method.
- Parameters
- ids : List[int]
IDs of entities in Supervisely.
- progress_cb : Callable
Function for control remove progress.
- Usage example
import supervisely as sly # You can connect to API directly address = 'https://app.supervise.ly/' token = 'Your Supervisely API Token' api = sly.Api(address, token) # Or you can use API from environment os.environ['SERVER_ADDRESS'] = 'https://app.supervisely.com' os.environ['API_TOKEN'] = 'Your Supervisely API Token' api = sly.Api.from_env() image_ids = [19369645, 19369646, 19369647] api.image.remove_batch(image_ids)
- upload_geometries_batch(figure_ids, geometries)¶
Upload figure geometries with given figure IDs to storage.