AnyGeometry

class AnyGeometry(sly_id=None, class_id=None, labeler_login=None, updated_at=None, created_at=None)[source]

Bases: Geometry

Placeholder geometry that accepts any shape type. Used for labels with flexible geometry. Immutable.

Parameters:
sly_id : int, optional

Geometry ID on Supervisely server.

class_id : int, optional

ObjClass ID.

labeler_login : str, optional

Labeler user login.

updated_at : int, optional

Last update timestamp.

created_at : int, optional

Creation timestamp.

Methods

allowed_transforms

Returns the allowed transforms for the Geometry.

clone

Clone from GEOMETRYYY

config_from_json

Convert geometry config from json format

config_to_json

Convert geometry config to json format

convert

Convert geometry to another geometry shape.

crop

Crop the geometry with given rectangle.

draw

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. per edge colors.

fliplr

flipud

from_json

Deserialize from a JSON-compatible dict :param data: JSON-compatible dict :returns: Parsed object

geometry_name

Geometry name.

get_mask

Returns 2D boolean mask of the geometry.

name

Get the name of the geometry.

relative_crop

Crops object like "crop" method, but return results with coordinates relative to rect :param rect: Rectangle for crop.

resize

rotate

Rotates around image center -> New Geometry :param rotator: Class for image rotation.

scale

Scales around origin with a given factor.

to_bbox

to_json

Serialize to JSON-compatible dict.

translate

validate

Validate geometry.

Attributes

area

classmethod allowed_transforms()

Returns the allowed transforms for the Geometry.

classmethod from_json(data)

Deserialize from a JSON-compatible dict :param data: JSON-compatible dict :returns: Parsed object

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

Convert geometry config from json format

Parameters:
config : dict

dictionary(geometry config) in json format

Returns:

dictionary(geometry config) in json format

Return type:

dict

static config_to_json(config)

Convert geometry config to json format

Parameters:
config : dict

dictionary(geometry config)

Returns:

dictionary(geometry config) in json format

Return type:

dict

static geometry_name()[source]

Geometry name.

Returns:

Geometry name

Return type:

str

clone()

Clone from GEOMETRYYY

convert(new_geometry, contour_radius=0, approx_epsilon=None)

Convert geometry to another geometry shape.

Parameters:
new_geometry

New geometry shape.

contour_radius : int

Radius of the contour.

approx_epsilon : float

Approximation epsilon.

Returns:

List of geometries.

Return type:

List[Geometry]

crop(rect)

Crop the geometry with given rectangle.

Parameters:
rect

Rectangle for crop.

Returns:

List of Geometry after crop.

Return type:

List[Geometry]`

draw(bitmap, color, thickness=1, config=None)
Parameters:
bitmap

np.ndarray

color

Color [R, G, B]

thickness=1

used only in Polyline and Point

config : dict

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

Raises:

NotImplementedError – if method is not implemented in subclass

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)
Parameters:
img_size : Tuple[int, int]

Image size (height, width) to which belongs Geometry.

Returns:

Geometry after flip in horizontal.

Return type:

Geometry

Raises:

NotImplementedError – if method is not implemented in subclass

flipud(img_size)
Parameters:
img_size : Tuple[int, int]

Image size (height, width) to which belongs Geometry.

Returns:

Geometry after flip in vertical.

Return type:

Geometry

Raises:

NotImplementedError – if method is not implemented in subclass

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

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)
Parameters:
in_size : Tuple[int, int]

Input image size (height, width).

out_size : Tuple[int, int]

Desired output image size (height, width) of the Annotation to which Label belongs.

Returns:

Geometry after resize.

Return type:

Geometry

Raises:

NotImplementedError – if method is not implemented in subclass

rotate(rotator)

Rotates around image center -> New Geometry :param rotator: Class for image rotation. :type rotator: ImageRotator :returns: Geometry after rotation. :rtype: Geometry

scale(factor)

Scales around origin with a given factor. :param: factor: Scale factor. :type factor: float :returns: Geometry :rtype: Geometry :raises NotImplementedError: if method is not implemented in subclass

to_bbox()
Returns:

Rectangle from geometry.

Return type:

Rectangle

Raises:

NotImplementedError – if method is not implemented in subclass

to_json()

Serialize to JSON-compatible dict. :returns: dict

translate(drow, dcol)
Parameters:
drow : int

Vertical shift.

dcol : int

Horizontal shift.

Returns:

Geometry after translate.

Return type:

Geometry

Raises:

NotImplementedError – if method is not implemented in subclass

validate(obj_class_shape, settings)

Validate geometry.

Parameters:
obj_class_shape : str

Object class shape.

settings : dict

Settings.

Raises:

ValueError – if geometry validation error

property area
Returns:

float