Cuboid¶
-
class Cuboid(points, faces, sly_id=
None, class_id=None, labeler_login=None, updated_at=None, created_at=None)[source]¶ Bases:
Geometry3D cuboid defined by eight corner points and six faces. Immutable.
Cuboid geometry for a single
Label.Cuboidclass object is immutable.- Parameters:
- points¶
List or tuple of
PointLocationobjects.- faces¶
List or tuple of
CuboidFaceobjects.- 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(
CuboidFaceobjects) != 3. A cuboid must have exactly 3 faces. Instead got {len(faces)} faces.ValueError – if point index is out of bounds for cuboid face. Got {len(points)!r} points, but the index is {point_idx!r}.
- 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
Returns the allowed transforms for the Geometry.
Clone from GEOMETRYYY
Convert geometry config from json format
Convert geometry config to json format
Convert geometry to another geometry shape.
Crops current Cuboid.
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.
Flips current Cuboid in horizontal.
Flips current Cuboid in vertical.
Convert a json dict to Cuboid.
Returns the name of the geometry.
Returns 2D boolean mask of the geometry.
Get the name of the geometry.
Crops object like "crop" method, but return results with coordinates relative to rect :param rect: Rectangle for crop.
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 geometry.
Attributes
Cuboid area.
List of
CuboidFaceobjects.List of
PointLocationobjects.- classmethod allowed_transforms()¶
Returns the allowed transforms for the Geometry.
- classmethod from_json(data)[source]¶
Convert a json dict to Cuboid. Read more about Supervisely format.
- Parameters:
- Returns:
Cuboid from json.
- 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)
- classmethod name()¶
Get the name of the geometry.
Same as
geometry_name(), but shorter. In order to make the code more concise.- Returns:
string with name of geometry
- static geometry_name()[source]¶
Returns the name of the geometry.
- Returns:
name of the geometry
- Return type:
- clone()¶
Clone from GEOMETRYYY
-
convert(new_geometry, contour_radius=
0, approx_epsilon=None)¶ Convert geometry to another geometry shape.
- crop(rect)[source]¶
Crops current Cuboid.
- Parameters:
- rect¶
Rectangle for crop.
- Returns:
List of Cuboids after crop.
- 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_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 after flip in horizontal.
- 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 after flip in vertical.
- 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))
- 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
- relative_crop(rect)¶
Crops object like “crop” method, but return results with coordinates relative to rect :param rect: Rectangle for crop. :type rect:
Rectangle:returns: List of Geometry after relative crop. :rtype: List[Geometry]` :raises NotImplementedError: if method is not implemented in subclass
- resize(in_size, out_size)[source]¶
Resize current Cuboid.
- Parameters:
- Returns:
Cuboid after resize.
- 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¶
Class for image rotation.
- Returns:
Cuboid after rotation.
- 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:
- Returns:
Cuboid after scale.
- 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 from 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) 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 after translate.
- 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)
- validate(obj_class_shape, settings)¶
Validate geometry.
- Parameters:
- Raises:
ValueError – if geometry validation error
- property area : float¶
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[supervisely.geometry.cuboid.CuboidFace]¶
List of
CuboidFaceobjects.- Returns:
Cuboid edges
- Return type:
List[
CuboidFace]
- property points : list[supervisely.geometry.point_location.PointLocation]¶
List of
PointLocationobjects.- Returns:
Cuboid nodes
- Return type:
List[
PointLocation]