VideoFigure

class VideoFigure(video_object, geometry, frame_index, key=None, class_id=None, labeler_login=None, updated_at=None, created_at=None, track_id=None, smart_tool_input=None, priority=None, status=None)[source]

Bases: object

Figure in video annotation: geometry tied to a VideoObject at a frame index. Immutable.

Parameters:
video_object

VideoObject for this figure.

geometry

Geometry (Rectangle, Polygon, etc.).

frame_index : int

Index of frame to which figure belongs.

key : uuid.UUID, optional

UUID key. Auto-generated if not provided.

class_id : int, optional

ID of VideoObject class.

labeler_login : str, optional

Login of user who created the figure.

updated_at : str, optional

Last modification timestamp.

created_at : str, optional

Creation timestamp.

track_id : str, optional

Track ID for tracking.

smart_tool_input : dict, optional

Smart Tool parameters from labeling.

priority : int, optional

Figure draw order (higher = on top).

status=None

Labeling status (manual, corrected, etc.).

Usage Example:
import supervisely as sly

obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)
fr_index = 7
geometry = sly.Rectangle(0, 0, 100, 100)
video_figure_car = sly.VideoFigure(video_obj_car, geometry, fr_index)
video_figure_car_json = video_figure_car.to_json()
print(video_figure_car_json)

Methods

clone

Makes a copy of VideoFigure with new fields, if fields are given, otherwise it will use fields of the original VideoFigure.

from_json

Convert a json dict to VideoFigure.

get_meta

Get metadata for the video figure.

key

Figure key.

to_json

Convert the VideoFigure to a json dict.

validate_bounds

Checks if given image with given size contains a figure.

Attributes

frame_index

Frame index of the current VideoFigure.

geometry

Geometry of the current VideoFigure.

parent_object

VideoObject of current VideoFigure.

priority

Priority of the figure (position of the figure relative to other overlapping or underlying figures).

smart_tool_input

Smart Tool parameters that were used for labeling.

status

Labeling status.

video_object

VideoObject of current VideoFigure.

classmethod from_json(data, objects, frame_index, key_id_map=None)[source]

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

Parameters:
data : dict

Dict in json format.

objects

VideoObjectCollection object.

frame_index : int

Index of Frame to which VideoFigure belongs.

key_id_map=None

KeyIdMap object.

Raises:

RuntimeError – if video object ID and video object key are None, if video object key and key_id_map are None, if video object with given id not found in key_id_map

Returns:

VideoFigure object

Return type:

VideoFigure

Usage Example:
import supervisely as sly

# Create VideoFigure from json we use data from example to_json(see above)
new_video_figure = sly.VideoFigure.from_json(video_figure_json, sly.VideoObjectCollection([video_obj_car]), fr_index)
clone(video_object=None, geometry=None, frame_index=None, key=None, class_id=None, labeler_login=None, updated_at=None, created_at=None, track_id=None, smart_tool_input=None, priority=None, status=None)[source]

Makes a copy of VideoFigure with new fields, if fields are given, otherwise it will use fields of the original VideoFigure.

Parameters:
video_object=None

VideoObject object.

geometry=None

Label Geometry object.

frame_index : int, optional

Index of Frame to which VideoFigure belongs.

key_id_map : KeyIdMap, optional

KeyIdMap object.

class_id : int, optional

ID of ObjClass to which VideoFigure belongs.

labeler_login : str, optional

Login of the user who created VideoFigure.

updated_at : str, optional

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

track_id : str, optional

ID of the track to which VideoFigure belongs.

smart_tool_input : dict, optional

Smart Tool parameters that were used for labeling.

priority : int, optional

Priority of the figure (position of the figure relative to other overlapping or underlying figures).

status=None

Sets labeling status. Specifies if the VideoFigure was created by NN model, manually or created by NN and then manually corrected.

Returns:

VideoFigure object

Return type:

VideoFigure

Usage Example:
import supervisely as sly

obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)
fr_index = 7
geometry = sly.Rectangle(0, 0, 100, 100)
video_figure_car = sly.VideoFigure(video_obj_car, geometry, fr_index)

obj_class_bus = sly.ObjClass('bus', sly.Rectangle)
video_obj_bus = sly.VideoObject(obj_class_bus)
fr_index_bus = 15
geometry_bus = sly.Rectangle(0, 0, 500, 600)

# Remember that VideoFigure object is immutable, and we need to assign new instance of VideoFigure to a new variable
video_figure_bus = video_figure_car.clone(video_object=video_obj_bus, geometry=geometry_bus, frame_index=fr_index_bus)
print(video_figure_bus.to_json())
# Output: {
#     "key": "c2f501e94f42483ebd202697608e8d26",
#     "objectKey": "942c79137b4547c59193276317f73897",
#     "geometryType": "rectangle",
#     "geometry": {
#         "points": {
#             "exterior": [
#                 [
#                     0,
#                     0
#                 ],
#                 [
#                     600,
#                     500
#                 ]
#             ],
#             "interior": []
#         }
#     }
# }
get_meta()[source]

Get metadata for the video figure.

Returns:

Dictionary with metadata for the video figure.

Return type:

Dict[str, int]

Usage Example:
import supervisely as sly

obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)
fr_index = 7
geometry = sly.Rectangle(0, 0, 100, 100)
video_figure_car = sly.VideoFigure(video_obj_car, geometry, fr_index)

print(video_figure_car.get_meta()) # {'frame': 7}
key()[source]

Figure key.

Returns:

Figure key.

Return type:

UUID

Usage Example:
key = video_figure_car.key
print(key) # 158e6cf4f4ac4c639fc6994aad127c16
to_json(key_id_map=None, save_meta=False)[source]

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

Parameters:
key_id_map=None

KeyIdMap object.

save_meta : bool, optional

Save frame index or not.

Returns:

Json format as a dict

Return type:

Dict

Usage Example:
import supervisely as sly

obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)
fr_index = 7
geometry = sly.Rectangle(0, 0, 100, 100)
video_figure_car = sly.VideoFigure(video_obj_car, geometry, fr_index)
video_figure_json = video_figure_car.to_json(save_meta=True)
print(video_figure_json)
# Output: {
#     "key": "591d0511ba28462c8cd657691743359c",
#     "objectKey": "e061bc50bd464c23a008b712d195570a",
#     "geometryType": "rectangle",
#     "geometry": {
#         "points": {
#             "exterior": [
#                 [
#                     0,
#                     0
#                 ],
#                 [
#                     100,
#                     100
#                 ]
#             ],
#             "interior": []
#         }
#     },
#     "meta": {"frame": 7},
#     "nnCreated": false,
#     "nnUpdated": false
# }
validate_bounds(img_size, _auto_correct=False)[source]

Checks if given image with given size contains a figure.

Parameters:
img_size : Tuple[int, int]

Size of the image (height, width).

_auto_correct : bool, optional

Correct the geometry of a shape if it is out of bounds or not.

:raises OutOfImageBoundsException: if figure is out of image bounds :returns: None :rtype: None

Usage Example:
import supervisely as sly

obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)
fr_index = 7
geometry = sly.Rectangle(0, 0, 100, 100)
video_figure_car = sly.VideoFigure(video_obj_car, geometry, fr_index)

im_size = (50, 200)
video_figure_car.validate_bounds(im_size)
# raise OutOfImageBoundsException("Figure is out of image bounds")
property frame_index : int

Frame index of the current VideoFigure.

Returns:

Index of Frame to which VideoFigure belongs

Return type:

int

Usage Example:
fr_index = video_figure_car.frame_index
print(fr_index) # 7
property geometry : supervisely.geometry.geometry.Geometry

Geometry of the current VideoFigure.

Returns:

Geometry object

Return type:

Geometry

Usage Example:
geometry = video_figure_car.geometry
print(geometry.to_json())
# Output: {
#     "points": {
#         "exterior": [
#             [
#                 0,
#                 0
#             ],
#             [
#                 100,
#                 100
#             ]
#         ],
#         "interior": []
#     }
# }
property parent_object : supervisely.video_annotation.video_object.VideoObject

VideoObject of current VideoFigure.

Returns:

VideoObject object

Return type:

VideoObject

Usage Example:
video_obj_car = video_figure_car.parent_object
print(video_obj_car.to_json())
# Output: {
#     "key": "d573c6f081544e3da20022d932b259c1",
#     "classTitle": "car",
#     "tags": []
# }
property priority

Priority of the figure (position of the figure relative to other overlapping or underlying figures).

property smart_tool_input

Smart Tool parameters that were used for labeling.

Example:

{

‘crop’: [[85.69912274538524, 323.07711452375236], [1108.5635719011857, 1543.1199742240174]], ‘visible’: True, ‘negative’: [], ‘positive’: [[597, 933], [474.5072466934964, 1381.6437133813354]]

}

property status : supervisely.annotation.label.LabelingStatus

Labeling status. Specifies if the VideoFigure was created by NN model, manually or created by NN and then manually corrected.

property video_object : supervisely.video_annotation.video_object.VideoObject

VideoObject of current VideoFigure.

Returns:

VideoObject object

Return type:

VideoObject

Usage Example:
video_obj_car = video_figure_car.video_object
print(video_obj_car.to_json())
# Output: {
#     "key": "d573c6f081544e3da20022d932b259c1",
#     "classTitle": "car",
#     "tags": []
# }