Polyline

class Polyline[source]

Bases: supervisely.geometry.vector_geometry.VectorGeometry

Polyline geometry for a single Label. Polyline class object is immutable.

Parameters
exterior : List[PointLocation], List[List[int, int]], List[Tuple[int, int]

List of exterior coordinates, the Polyline is defined with these points.

sly_id : int, optional

Polyline ID in Supervisely server.

class_id : int, optional

ID of ObjClass to which Polyline belongs.

labeler_login : str, optional

Login of the user who created Polyline.

updated_at : str, optional

Date and Time when Polyline 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 Polyline was created. Date Format is the same as in “updated_at” parameter.

Raises

ValueError, field exterior must contain at least two points to create Polyline object

Usage example
import supervisely as sly

exterior = [sly.PointLocation(730, 2104), sly.PointLocation(2479, 402), sly.PointLocation(1500, 780)]
# or exterior = [[730, 2104], [2479, 402], [1500, 780]]
# or exterior = [(730, 2104), (2479, 402), (1500, 780)]
figure = sly.Polyline(exterior)

Methods

allowed_transforms

approx_dp

Approximates a Polyline with the specified precision.

clone

Clone from GEOMETRYYY

config_from_json

config_to_json

convert

crop

Crops current Polyline.

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

Flips current VectorGeometry in horizontal.

flipud

Flips current VectorGeometry in vertical.

from_json

Convert a json dict to Polyline.

geometry_name

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

Resizes current VectorGeometry.

rotate

Rotates current VectorGeometry.

scale

Scales current VectorGeometry.

to_bbox

Creates Rectangle object from current VectorGeometry.

to_json

Convert the VectorGeometry to a json dict.

translate

Translates current VectorGeometry.

validate

Attributes

area

Polyline area, always 0.0.

exterior

VectorGeometry exterior points.

exterior_np

Converts exterior attribute of VectorGeometry to numpy array.

interior

VectorGeometry interior points.

interior_np

Converts interior attribute of VectorGeometry to numpy array.

classmethod allowed_transforms()[source]
approx_dp(epsilon)[source]

Approximates a Polyline with the specified precision.

Parameters
epsilon : float

Specifying the approximation accuracy.

Returns

Polyline object

Return type

Polyline

Usage Example
# Remember that Polyline class object is immutable, and we need to assign new instance of Polyline to a new variable
approx_figure = figure.approx_dp(0.75)
clone()

Clone from GEOMETRYYY

crop(rect)[source]

Crops current Polyline.

Parameters
rect : Rectangle

Rectangle object for crop.

Returns

List of Polyline objects

Return type

List[Polyline]

Usage Example
import supervisely as sly

crop_figures = figure.crop(sly.Rectangle(0, 0, 100, 200))
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)

Flips current VectorGeometry in horizontal.

Parameters
img_size : Tuple[int, int]

Input image size (height, width) to which belongs VectorGeometry.

Returns

VectorGeometry object

Return type

VectorGeometry

Usage Example
# Remember that VectorGeometry class object is immutable, and we need to assign new instance of VectorGeometry to a new variable
height, width = 300, 400
fliplr_figure = figure.fliplr((height, width))
flipud(img_size)

Flips current VectorGeometry in vertical.

Parameters
img_size : Tuple[int, int]

Input image size (height, width) to which belongs VectorGeometry.

Returns

VectorGeometry object

Return type

VectorGeometry

Usage Example
# Remember that VectorGeometry class object is immutable, and we need to assign new instance of VectorGeometry to a new variable
height, width = 300, 400
flipud_figure = figure.flipud((height, width))
classmethod from_json(data)[source]

Convert a json dict to Polyline. Read more about Supervisely format.

Parameters
data : dict

Polyline in json format as a dict.

Returns

Polyline object

Return type

Polyline

Usage example
import supervisely as sly

figure_json = {
    "points": {
        "exterior": [
            [2104, 730],
            [402, 2479],
            [780, 1500]
        ],
        "interior": []
    }
}
figure = sly.Polyline.from_json(figure_json)
static geometry_name()[source]
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

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)

Resizes current VectorGeometry.

Parameters
in_size : Tuple[int, int]

Input image size (height, width) to which belongs VectorGeometry.

out_size : Tuple[int, int]

Desired output image size (height, width) to which belongs VectorGeometry.

Returns

VectorGeometry object

Return type

VectorGeometry

Usage Example
# Remember that VectorGeometry class object is immutable, and we need to assign new instance of VectorGeometry 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 VectorGeometry.

Parameters
rotator : ImageRotator

ImageRotator object for rotate.

Returns

VectorGeometry object

Return type

VectorGeometry

Usage Example
from supervisely.geometry.image_rotator import ImageRotator

# Remember that VectorGeometry class object is immutable, and we need to assign new instance of VectorGeometry to a new variable
height, width = 300, 400
rotator = ImageRotator((height, width), 25)
rotate_figure = figure.rotate(rotator)
scale(factor)

Scales current VectorGeometry.

Parameters
factor : float

Scale parameter.

Returns

VectorGeometry object

Return type

VectorGeometry

Usage Example
# Remember that VectorGeometry class object is immutable, and we need to assign new instance of VectorGeometry to a new variable
scale_figure = figure.scale(0.75)
to_bbox()

Creates Rectangle object from current VectorGeometry.

Returns

Rectangle object

Return type

Rectangle

Usage Example
rectangle = figure.to_bbox()
to_json()

Convert the VectorGeometry to a json dict. Read more about Supervisely format.

Returns

Json format as a dict

Return type

dict

Usage example
figure_json = figure.to_json()
print(figure_json)
# Output: {
#    "points": {
#        "exterior": [
#            [2104, 730],
#            [402, 2479],
#            [1646, 3746]
#        ],
#        "interior": [
#            [
#                [1255, 1907],
#                [875, 2468],
#                [1577, 2679]
#            ]
#        ]
#    }
# }
translate(drow, dcol)

Translates current VectorGeometry.

Parameters
drow : int

Horizontal shift.

dcol : int

Vertical shift.

Returns

VectorGeometry object

Return type

VectorGeometry

Usage Example
# Remember that VectorGeometry class object is immutable, and we need to assign new instance of VectorGeometry to a new variable
translate_figure = figure.translate(150, 250)
property area

Polyline area, always 0.0.

Returns

Area of current Polyline

Return type

float

Usage Example
print(figure.area)
# Output: 0.0
property exterior

VectorGeometry exterior points.

Returns

VectorGeometry exterior points

Return type

List[PointLocation]

Usage example
exterior = figure.exterior
property exterior_np

Converts exterior attribute of VectorGeometry to numpy array.

Returns

Numpy array

Return type

np.ndarray

Usage example
print(figure.exterior_np)
# Output:
# [[ 730 2104]
#  [2479  402]
#  [3746 1646]]
property interior

VectorGeometry interior points.

Returns

VectorGeometry interior points

Return type

List[List[PointLocation]]

Usage example
interior = figure.interior
property interior_np

Converts interior attribute of VectorGeometry to numpy array.

Returns

Numpy array

Return type

List[np.ndarray]

Usage example
print(figure.interior_np)
# Output:
# [array([[1907, 1255],
#        [2468,  875],
#        [2679, 1577]])]