pointcloud

Functions

get_labeling_tool_link(url[, name])

Get HTML link to the labeling tool with the specified URL and name.

get_labeling_tool_url(dataset_id, pointcloud_id)

Get the URL for the labeling tool with the specified dataset ID and point cloud ID.

has_valid_ext(path)

Checks if file from given path with given extention is supported

is_valid_ext(ext)

Checks if given extention is supported.

is_valid_format(path)

Checks if Pointcloud file from given path has supported extension.

read(path[, coords_dims])

Loads a pointcloud from the specified file and returns it in XYZ format.

validate_ext(ext)

Raise error if given extention is not supported

validate_format(path)

Raise error if file from given path with given extention is not supported

write(path, pointcloud_np[, coords_dims])

Saves a pointcloud to the specified file.

Description

Functions for processing pointclouds

Get HTML link to the labeling tool with the specified URL and name.

Parameters
url : str

URL of the labeling tool.

name : str

Name of the link, default is “open in labeling tool”.

Returns

HTML link to the labeling tool with the specified URL and name.

Return type

str

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()

# Pass values into the API constructor (optional, not recommended)
# api = sly.Api(server_address="https://app.supervise.ly", token="4r47N...xaTatb")

pointcloud_id = 19373403
pcd_info = api.pointcloud.get_info_by_id(pointcloud_id)
url = sly.pointcloud.get_labeling_tool_url(pcd_info.dataset_id, pcd_info.id)
name = "my link"

link = sly.pointcloud.get_labeling_tool_link(url, name)

print(link)
# Output:
# <a
#     href="https://dev.supervise.ly/app/point-clouds/?datasetId=55875&pointCloudId=19373403"
#     rel="noopener noreferrer"
#     target="_blank"
# >
#     my link<i class="zmdi zmdi-open-in-new" style="margin-left: 5px"></i>
# </a>
get_labeling_tool_url(dataset_id, pointcloud_id)[source]

Get the URL for the labeling tool with the specified dataset ID and point cloud ID.

Parameters
dataset_id : int

Dataset ID in Supervisely.

pointcloud_id : int

Point cloud ID in Supervisely.

Returns

URL for the labeling tool with the specified dataset ID and point cloud ID

Return type

str

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()

# Pass values into the API constructor (optional, not recommended)
# api = sly.Api(server_address="https://app.supervise.ly", token="4r47N...xaTatb")

pointcloud_id = 19373403
pcd_info = api.pointcloud.get_info_by_id(pointcloud_id)
url = sly.pointcloud.get_labeling_tool_url(pcd_info.dataset_id, pcd_info.id)

print(url)
# Output:
# https://dev.supervise.ly/app/point-clouds/?datasetId=55875&pointCloudId=19373403
has_valid_ext(path)[source]

Checks if file from given path with given extention is supported

Parameters
path : str

Pointcloud file path.

Returns

bool

Return type

bool

Usage example

import supervisely as sly

path = "/Users/Downloads/demo_pointcloud-2/LYFT/1231201437602160096.pcd"
sly.pointcloud.has_valid_ext(path)  # True
sly.pointcloud.has_valid_ext(path) # False
is_valid_ext(ext)[source]

Checks if given extention is supported.

Parameters
ext : str

Pointcloud file extension.

Returns

bool

Return type

bool

Usage example

import supervisely as sly

sly.pointcloud.is_valid_ext(".pcd")  # True
sly.pointcloud.is_valid_ext(".mp4") # False
is_valid_format(path)[source]

Checks if Pointcloud file from given path has supported extension.

Parameters
path : str

Path to Pointcloud file.

Returns

True if file format in list of supported pointcloud formats, False - in otherwise

Return type

bool

Usage example
import supervisely as sly

pcd_path = "/pointclouds/pcd0001.jpg"
sly.pointcloud.is_valid_format(pcd_path) # False
read(path, coords_dims=None)[source]

Loads a pointcloud from the specified file and returns it in XYZ format.

Parameters
path : str

Path to file.

Returns

Numpy array

Return type

np.ndarray

Usage example
import supervisely as sly

pcd_np = sly.pointcloud.read('/home/admin/work/pointclouds/ptc0.pcd')
validate_ext(ext)[source]

Raise error if given extention is not supported

Parameters
ext : str

Pointcloud file extension.

Returns

None

Return type

NoneType

Usage example

import supervisely as sly

sly.pointcloud.validate_ext(".mp4")

# UnsupportedPointcloudFormat: Unsupported pointcloud extension: .mp4.
# Only the following extensions are supported: ['.pcd'].
validate_format(path)[source]

Raise error if file from given path with given extention is not supported

Parameters
path : str

Pointcloud file path.

Returns

None

Return type

NoneType

Usage example
import supervisely as sly

path = "/Downloads/videos/111.mp4"
sly.pointcloud.validate_format(path)

# UnsupportedPointcloudFormat: Unsupported pointcloud extension: .mp4.
# Only the following extensions are supported: ['.pcd'].
write(path, pointcloud_np, coords_dims=None)[source]

Saves a pointcloud to the specified file. It creates directory from path if the directory for this path does not exist.

Parameters
path : str

Path to file.

pointcloud_np : np.ndarray

Pointcloud [N, 3] in XYZ format.

coords_dims : Optional[List[int]]

List of indexes for (X, Y, Z) coords. Default (if None): [0, 1, 2].

Returns

Success or not.

Return type

bool

Usage example
import supervisely as sly
import numpy as np

pointcloud = np.random.randn(100, 3)

ptc = sly.pointcloud.write('/home/admin/work/pointclouds/ptc0.pcd', pointcloud)