Geometry

class Geometry[source]

Bases: supervisely.io.json.JsonSerializable

Methods

allowed_transforms

clone

Clone from GEOMETRYYY

config_from_json

config_to_json

convert

crop

param rect

Rectangle

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

param img_size

(rows, cols)

flipud

param img_size

(rows, cols)

from_json

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

geometry_name

return

string with name of geometry

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

param in_size

(rows, cols)

rotate

Rotates around image center -> New Geometry :param rotator: ImageRotator :return: Geometry

scale

Scales around origin with a given factor.

to_bbox

return

Rectangle

to_json

Serialize to JSON-compatible dict.

translate

param drow

int rows shift

validate

Attributes

area

return

float

clone()[source]

Clone from GEOMETRYYY

crop(rect)[source]
Parameters
rect

Rectangle

Returns

list of Geometry

draw(bitmap, color, thickness=1, config=None)[source]
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)[source]

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]
Parameters
img_size

(rows, cols)

Returns

Geometry

flipud(img_size)[source]
Parameters
img_size

(rows, cols)

Returns

Geometry

classmethod from_json(data)

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

static geometry_name()[source]
Returns

string with name of geometry

get_mask(img_size)[source]

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()[source]

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

Returns

string with name of geometry

relative_crop(rect)[source]

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]
Parameters
in_size

(rows, cols)

out_size

(128, 256) (128, KEEP_ASPECT_RATIO) (KEEP_ASPECT_RATIO, 256)

Returns

Geometry

rotate(rotator)[source]

Rotates around image center -> New Geometry :param rotator: ImageRotator :return: Geometry

scale(factor)[source]

Scales around origin with a given factor. :param: factor (float): :return: Geometry

to_bbox()[source]
Returns

Rectangle

to_json()

Serialize to JSON-compatible dict. :return: dict

translate(drow, dcol)[source]
Parameters
drow

int rows shift

dcol

int cols shift

Returns

Geometry

property area
Returns

float