Cuboid

class Cuboid[source]

Bases: supervisely.geometry.geometry.Geometry

Cuboid geometry for a single Label. Cuboid class object is immutable.

Parameters
points : List[PointLocation] or Tuple[PointLocation]

List or tuple of PointLocation objects.

faces : List[CuboidFace] or Tuple[CuboidFace]

List or tuple of CuboidFace objects.

sly_id : int, optional

Cuboid ID in Supervisely server.

class_id : int, optional

ID for ObjClass to which belongs Cuboid.

labeler_login : str, optional

Login of the user who created Cuboid.

updated_at : str, optional

Date and Time when Cuboid was modified last. Date Format: Year:Month:Day:Hour:Minute:Seconds. Example: ‘2021-01-22T19:37:50.158Z’.

created_at : str, optional

Date and Time when Cuboid was created. Date Format is the same as in “updated_at” parameter.

Raises

ValueError, if len(faces) != 3

Usage example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

Methods

allowed_transforms

clone

Clone from GEOMETRYYY

config_from_json

config_to_json

convert

crop

Crops current Cuboid.

draw

param bitmap

np.ndarray

draw_contour

Draws the figure contour on a given bitmap canvas :param bitmap: np.ndarray :param color: [R, G, B] :param thickness: (int) :param config: drawing config specific to a concrete subclass, e.g.

fliplr

Flips current Cuboid in horizontal.

flipud

Flips current Cuboid in vertical.

from_json

Convert a json dict to Cuboid.

geometry_name

get_mask

Returns 2D boolean mask of the geometry.

name

Same as geometry_name(), but shorter.

relative_crop

Crops object like "crop" method, but return results with coordinates relative to rect :param rect: :return: list of Geometry

resize

Resize current Cuboid.

rotate

Rotates current Cuboid.

scale

Scale current Cuboid.

to_bbox

Create Rectangle object from current Cuboid.

to_json

Convert the Cuboid to a json dict.

translate

Translate current Cuboid.

validate

Attributes

area

Cuboid area.

faces

List of CuboidFace objects.

points

List of PointLocation objects.

clone()

Clone from GEOMETRYYY

crop(rect)[source]

Crops current Cuboid.

Parameters
rect : Rectangle

Rectangle object for crop.

Returns

List of Cuboid objects

Return type

List[Cuboid]

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)
crop_figures = figure.crop(sly.Rectangle(1, 1, 1500, 1550))
draw(bitmap, color, thickness=1, config=None)
Parameters
bitmap

np.ndarray

color

[R, G, B]

thickness

used only in Polyline and Point

config

drawing config specific to a concrete subclass, e.g. per edge colors

draw_contour(bitmap, color, thickness=1, config=None)

Draws the figure contour on a given bitmap canvas :param bitmap: np.ndarray :param color: [R, G, B] :param thickness: (int) :param config: drawing config specific to a concrete subclass, e.g. per edge colors

fliplr(img_size)[source]

Flips current Cuboid in horizontal.

Parameters
img_size : Tuple[int, int]

Image size (height, width) to which belongs Cuboid object.

Returns

Cuboid object

Return type

Cuboid

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

# Remember that Cuboid class object is immutable, and we need to assign new instance of Cuboid to a new variable
height, width = 1250, 1400
fliplr_figure = figure.fliplr((height, width))
flipud(img_size)[source]

Flips current Cuboid in vertical.

Parameters
img_size : Tuple[int, int]

Image size (height, width) to which belongs Cuboid object.

Returns

Cuboid object

Return type

Cuboid

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

# Remember that Cuboid class object is immutable, and we need to assign new instance of Cuboid to a new variable
height, width = 1250, 1400
flipud_figure = figure.flipud((height, width))
classmethod from_json(data)[source]

Convert a json dict to Cuboid. Read more about Supervisely format.

Parameters
data : dict

Cuboid in json format as a dict.

Returns

Cuboid object

Return type

Cuboid

Raises

ValueError if json format is not correct

Usage example
import supervisely as sly

data = {
    "faces": [
                [0, 1, 2, 3],
                [0, 4, 5, 1],
                [1, 5, 6, 2]
    ],
    "points": [
                [273, 277],
                [273, 840],
                [690, 840],
                [690, 277],
                [168, 688],
                [168, 1200],
                [522, 1200]
    ]
}

figure = sly.Cuboid.from_json(data)
static geometry_name()[source]
get_mask(img_size)

Returns 2D boolean mask of the geometry. With shape as img_size (height, width) and filled with True values inside the geometry and False values outside. dtype = np.bool shape = img_size

Parameters
img_size : Tuple[int, int]

size of the image (height, width)

Returns

2D boolean mask of the geometry

Return type

np.ndarray

classmethod name()

Same as geometry_name(), but shorter. In order to make the code more concise.

Returns

string with name of geometry

relative_crop(rect)

Crops object like “crop” method, but return results with coordinates relative to rect :param rect: :return: list of Geometry

resize(in_size, out_size)[source]

Resize current Cuboid.

Parameters
in_size : Tuple[int, int]

Input image size (height, width) to which belongs Cuboid object.

out_size : Tuple[int, int]

Desired output image size (height, width) to which belongs Cuboid object.

Returns

Cuboid object

Return type

Cuboid

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

# Remember that Cuboid class object is immutable, and we need to assign new instance of Cuboid to a new variable
in_height, in_width = 1250, 1400
out_height, out_width = 600, 800
resize_figure = figure.resize((in_height, in_width), (out_height, out_width))
rotate(rotator)[source]

Rotates current Cuboid.

Parameters
rotator : ImageRotator

ImageRotator object for rotation.

Returns

Cuboid object

Return type

Cuboid

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace
from supervisely.geometry.image_rotator import ImageRotator

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

# Remember that Cuboid class object is immutable, and we need to assign new instance of Cuboid to a new variable
rotator = ImageRotator((300, 400), 25)
rotate_fugure= figure.rotate(rotator)
scale(factor)[source]

Scale current Cuboid.

Parameters
factor : float

Scale parameter.

Returns

Cuboid object

Return type

Cuboid

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

# Remember that Cuboid class object is immutable, and we need to assign new instance of Cuboid to a new variable
scale_figure = figure.scale(1.75)
to_bbox()[source]

Create Rectangle object from current Cuboid.

Returns

Rectangle object

Return type

Rectangle

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

rectangle = figure.to_bbox()
to_json()[source]

Convert the Cuboid to a json dict. Read more about Supervisely format.

Returns

Json format as a dict

Return type

dict

Usage example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

figure_json = figure.to_json()
print(figure_json)
# Output: {
#    "faces": [
#        [0, 1, 2, 3],
#        [0, 4, 5, 1],
#        [1, 5, 6, 2]
#    ],
#    "points": [
#        [273, 277],
#        [273, 840],
#        [690, 840],
#        [690, 277],
#        [168, 688],
#        [168, 1200],
#        [522, 1200]
#    ]
# }
translate(drow, dcol)[source]

Translate current Cuboid.

Parameters
drow : int

Horizontal shift.

dcol : int

Vertical shift.

Returns

Cuboid object

Return type

Cuboid

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

# Remember that Cuboid class object is immutable, and we need to assign new instance of Cuboid to a new variable
translate_figure = figure.translate(150, 350)
property area

Cuboid area.

Returns

Area of current Cuboid

Return type

float

Usage Example
import supervisely as sly
from supervisely.geometry.cuboid import CuboidFace

nodes = [[277, 273], [840, 273], [840, 690], [277, 690], [688, 168], [1200, 168], [1200, 522]]
edges = [CuboidFace(0, 1, 2, 3), CuboidFace(0, 4, 5, 1), CuboidFace(1, 5, 6, 2)]
pl_nodes = (sly.PointLocation(node[0], node[1]) for node in nodes)
figure = sly.Cuboid(pl_nodes, edges)

print(figure.area)
# Output: 5146.0
property faces

List of CuboidFace objects.

Returns

Cuboid edges

Return type

List[CuboidFace]

property points

List of PointLocation objects.

Returns

Cuboid nodes

Return type

List[PointLocation]