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 from GEOMETRYYY
config_from_json
config_to_json
convert
Crops current Cuboid.
- param bitmap
np.ndarray
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.
Flips current Cuboid in horizontal.
Flips current Cuboid in vertical.
Convert a json dict to Cuboid.
Returns 2D boolean mask of the geometry.
Same as geometry_name(), but shorter.
Crops object like "crop" method, but return results with coordinates relative to rect :param rect: :return: list of Geometry
Resize current Cuboid.
Rotates current Cuboid.
Scale current Cuboid.
Create Rectangle object from current Cuboid.
Convert the Cuboid to a json dict.
Translate current Cuboid.
validate
Attributes
Cuboid area.
List of
CuboidFace
objects.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
- 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
- Returns
Cuboid object
- Return type
- 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
- Returns
Cuboid object
- Return type
- 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
- 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)
- 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
- 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
- Returns
Cuboid object
- Return type
- 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
- 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
- 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
- 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
- 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
- Returns
Cuboid object
- Return type
- 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
- 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]