Video Figure

exception supervisely_lib.video_annotation.video_figure.OutOfImageBoundsExtension[source]

Bases: Exception

class supervisely_lib.video_annotation.video_figure.VideoFigure(video_object: supervisely_lib.video_annotation.video_object.VideoObject, geometry: supervisely_lib.geometry.geometry.Geometry, frame_index: int, key: Optional[uuid.UUID] = None, class_id: Optional[int] = None, labeler_login: Optional[str] = None, updated_at: Optional[str] = None, created_at: Optional[str] = None)[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
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": []
#         }
#     }
# }
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": []
# }
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 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 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
key()[source]
to_json(key_id_map: Optional[uuid.UUID] = None, save_meta: bool = False) → dict[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
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
#     }
# }
classmethod from_json(data: dict, objects: supervisely_lib.video_annotation.video_object_collection.VideoObjectCollection, frame_index: int, key_id_map: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None)supervisely_lib.video_annotation.video_figure.VideoFigure[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
# 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: Optional[supervisely_lib.video_annotation.video_object.VideoObject] = None, geometry: Optional[supervisely_lib.geometry.geometry.Geometry] = None, frame_index: Optional[int] = None, key: Optional[uuid.UUID] = None, class_id: Optional[int] = None, labeler_login: Optional[str] = None, updated_at: Optional[str] = None, created_at: Optional[str] = None)supervisely_lib.video_annotation.video_figure.VideoFigure[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
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": []
#         }
#     }
# }
validate_bounds(img_size: Tuple[int, int], _auto_correct: bool = False) → None[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

OutOfImageBoundsExtension, if figure is out of image bounds

Returns

None

Return type

NoneType

Usage Example
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 OutOfImageBoundsExtension("Figure is out of image bounds")