Cuboid2d¶
-
class Cuboid2d(nodes, sly_id=
None, class_id=None, labeler_login=None, updated_at=None, created_at=None, position=None, rotation=None, dimensions=None, face=None)[source]¶ Bases:
GraphNodes2D projection of cuboid as a graph of keypoints (eight corners). Immutable.
Cuboid2d geometry for a single
Label.Cuboid2dclass object is immutable.- Parameters:
- nodes : dict¶
Dict or List containing nodes of graph
- sly_id : int, optional¶
Cuboid2d ID in Supervisely server.
- class_id : int, optional¶
ID of ObjClass to which Cuboid2d belongs.
- labeler_login : str, optional¶
Login of the user who created
Cuboid2d.- updated_at : str, optional¶
Date and Time when Cuboid2d 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 Cuboid2d was created. Date Format is the same as in “updated_at” parameter.
- Usage Example:
import supervisely as sly from supervisely.geometry.graph import Node, Cuboid2d vertex_1 = Node(sly.PointLocation(5, 5)) vertex_2 = Node(sly.PointLocation(100, 100)) vertex_3 = Node(sly.PointLocation(200, 250)) nodes = {0: vertex_1, 1: vertex_2, 2: vertex_3} figure = Cuboid2d(nodes)
Methods
Returns the allowed transforms for the Cuboid2d.
Makes a copy of the GraphNodes.
Convert graph template from json format
Convert graph template to json format
Convert geometry to another geometry shape.
Crops current GraphNodes.
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 GraphNodes in horizontal.
Flips current GraphNodes in vertical.
Convert a json dict to Cuboid2d.
geometry_nameReturns 2D boolean mask of the geometry.
Get the name of the geometry.
Crops current GraphNodes with given rectangle and shifts it on value of rectangle left top angle.
Resizes current GraphNodes.
Rotates current GraphNodes.
Scales current GraphNodes.
Create Rectangle object from current GraphNodes.
Convert the Cuboid2d to list.
Translates current GraphNodes.
Checks the graph for correctness and compliance with the template
Attributes
GraphNodes area.
Copy of the dimensions of the Cuboid2d.
Copy of the face of the Cuboid2d.
items_json_fieldCopy of GraphNodes nodes.
Copy of the position of the Cuboid2d.
Copy of the rotation of the Cuboid2d.
Copy of Cuboid2d vertices.
- classmethod from_json(data)[source]¶
Convert a json dict to Cuboid2d. Read more about Supervisely format.
- Parameters:
- Returns:
Cuboid2d from json.
- Return type:
- Usage Example:
figure_json = { "vertices": { "0": {"loc": [5, 5]}, "1": {"loc": [100, 100]}, "2": {"loc": [250, 200]}, "position": { "x": 0.0657651107620552, "y": -0.05634319555373257, "z": 0.7267282757573887 }, "rotation": { "x": 0, "y": 0, "z": 0 }, "dimensions": { "x": 0.1425456564648202, "y": 0.1, "z": 0.36738880874660756 }, "face": [ "face2-topleft", "face2-topright", "face2-bottomright", "face2-bottomleft" ] } } from supervisely.geometry.graph import Cuboid2d figure = Cuboid2d.from_json(figure_json)
- 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
- clone()¶
Makes a copy of the GraphNodes.
- Returns:
Copy of GraphNodes.
- Return type:
- Usage Example:
# Remember that GraphNodes class object is immutable, and we need to assign new instance of PointLocation to a new variable new_figure = figure.clone()
-
convert(new_geometry, contour_radius=
0, approx_epsilon=None)¶ Convert geometry to another geometry shape.
- crop(rect)¶
Crops current GraphNodes.
- Parameters:
- rect¶
Rectangle for crop.
- Returns:
List of GraphNodes after crop.
- Return type:
List[
GraphNodes]- Usage Example:
import supervisely as sly crop_figures = figure.crop(sly.Rectangle(0, 0, 300, 350))
-
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)¶
Flips current GraphNodes in horizontal.
- Parameters:
- img_size : Tuple[int, int]¶
Input image size (height, width) to which belongs
GraphNodes.
- Returns:
GraphNodes after flip in horizontal.
- Return type:
- Usage Example:
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 fliplr_figure = figure.fliplr((height, width))
- flipud(img_size)¶
Flips current GraphNodes in vertical.
- Parameters:
- Returns:
GraphNodes after flip in vertical.
- Return type:
- Usage Example:
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 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 current GraphNodes with given rectangle and shifts it on value of rectangle left top angle.
- Parameters:
- rect¶
Rectangle for crop.
- Returns:
List of GraphNodes after relative crop.
- Return type:
List[
GraphNodes]- Usage Example:
import supervisely as sly rel_crop_figures = figure.relative_crop(sly.Rectangle(0, 0, 300, 350))
- resize(in_size, out_size)¶
Resizes current GraphNodes.
- Parameters:
- in_size : Tuple[int, int]¶
Input image size (height, width) to which belongs
GraphNodes.- out_size : Tuple[int, int]¶
Desired output image size (height, width) to which belongs
GraphNodes.
- Returns:
GraphNodes after resize.
- Return type:
- Usage Example:
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable in_height, in_width = 300, 400 out_height, out_width = 600, 800 resize_figure = figure.resize((in_height, in_width), (out_height, out_width))
- rotate(rotator)¶
Rotates current GraphNodes.
- Parameters:
- rotator¶
Class for image rotation.
- Returns:
GraphNodes after rotation.
- Return type:
- Usage Example:
from supervisely.geometry.image_rotator import ImageRotator # Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable height, width = 300, 400 rotator = ImageRotator((height, width), 25) rotate_figure = figure.rotate(rotator)
- scale(factor)¶
Scales current GraphNodes.
- Parameters:
- Returns:
GraphNodesobject- Return type:
- Usage Example:
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable scale_figure = figure.scale(0.75)
- to_bbox()¶
Create Rectangle object from current GraphNodes.
- Returns:
Rectangle from GraphNodes.
- Return type:
- Usage Example:
rectangle = figure.to_bbox()
- to_json()[source]¶
Convert the Cuboid2d to list. Read more about Supervisely format.
- Returns:
Json format as a dict
- Return type:
Dict[str, Dict]
- Usage Example:
import supervisely as sly from supervisely.geometry.graph import Node, Cuboid2d vertex_1 = Node(sly.PointLocation(5, 5)) vertex_2 = Node(sly.PointLocation(100, 100)) vertex_3 = Node(sly.PointLocation(200, 250)) nodes = {0: vertex_1, 1: vertex_2, 2: vertex_3} figure = Cuboid2d(nodes) figure_json = figure.to_json() print(figure_json) # Output: { # "nodes": { # "0": { # "loc": [5, 5] # }, # "1": { # "loc": [100, 100] # }, # "2": { # "loc": [250, 200] # } # }, # "position": { # "x": 0.0657651107620552, # "y": -0.05634319555373257, # "z": 0.7267282757573887 # }, # "rotation": { "x": 0, "y": 0, "z": 0 }, # "dimensions": { # "x": 0.1425456564648202, # "y": 0.1, # "z": 0.36738880874660756 # }, # "face": [ # "face2-topleft", # "face2-topright", # "face2-bottomright", # "face2-bottomleft" # ], # }
- transform(transform_fn)¶
- Parameters:
- transform_fn : function¶
Function to convert GraphNodes.
- Returns:
GraphNodes after transformation.
- Return type:
- transform_locations(transform_fn)¶
- Parameters:
- transform_fn : function¶
Function to convert GraphNodes location.
- Returns:
GraphNodes after transformation.
- Return type:
- translate(drow, dcol)¶
Translates current GraphNodes.
- Parameters:
- Returns:
GraphNodes after translate.
- Return type:
- Usage Example:
# Remember that GraphNodes class object is immutable, and we need to assign new instance of Rectangle to a new variable translate_figure = figure.translate(150, 250)
- property area : float¶
GraphNodes area.
- Returns:
Area of current GraphNodes, always 0.0
- Return type:
- Usage Example:
print(figure.area) # Output: 0.0
- property position : dict | None¶
Copy of the position of the Cuboid2d.
- Returns:
Position of the
Cuboid2d- Return type:
Optional[Dict]