VideoFigure

class VideoFigure[source]

Bases: object

VideoFigure object for VideoAnnotation. VideoFigure object is immutable.

Parameters
video_object : VideoObject

VideoObject object.

geometry : Geometry

Label geometry.

frame_index : int

Index of Frame to which VideoFigure belongs.

key_id_map : KeyIdMap, optional

KeyIdMap object.

class_id : int, optional

ID of VideoObject 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.

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)
# Output: {
#     "key": "5e8afd2e26a54ab18154b355fa9665f8",
#     "objectKey": "5860b7a5519b4de7b3d9c1720a40b38a",
#     "geometryType": "rectangle",
#     "geometry": {
#         "points": {
#             "exterior": [
#                 [
#                     0,
#                     0
#                 ],
#                 [
#                     100,
#                     100
#                 ]
#             ],
#             "interior": []
#         }
#     }
# }

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.

video_object

VideoObject of current VideoFigure.

clone(video_object=None, geometry=None, frame_index=None, key=None, class_id=None, labeler_login=None, updated_at=None, created_at=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 : VideoObject, optional

VideoObject object.

geometry : Geometry, optional

Label geometry.

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.

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": []
#         }
#     }
# }
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

VideoObjectCollection object.

frame_index : int

Index of Frame to which VideoFigure belongs.

key_id_map : KeyIdMap, optional

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)
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 : KeyIdMap, optional

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
#     }
# }
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

Return type

NoneType

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

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

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

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 video_object

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": []
# }