Video Object

class supervisely_lib.video_annotation.video_object.VideoObject(obj_class: supervisely_lib.annotation.obj_class.ObjClass, tags: Optional[supervisely_lib.video_annotation.video_tag_collection.VideoTagCollection] = None, key: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None, class_id: Optional[int] = None, labeler_login: Optional[str] = None, updated_at: Optional[str] = None, created_at: Optional[str] = None)[source]

Bases: supervisely_lib.collection.key_indexed_collection.KeyObject

VideoObject object for VideoAnnotation. VideoObject object is immutable.

Parameters
  • obj_class (ObjClass) – VideoObject class.

  • tags (VideoTagCollection, optional) – VideoObject tags.

  • key (KeyIdMap, optional) – KeyIdMap object.

  • class_id (int, optional) – ID of ObjClass to which VideoObject belongs.

  • labeler_login (str, optional) – Login of the user who created VideoObject.

  • updated_at (str, optional) – Date and Time when VideoObject 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 VideoObject 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)
video_obj_car_json = video_obj_car.to_json()
print(video_obj_car_json)
# Output: {
#     "key": "6b819f1840f84d669b32cdec225385f0",
#     "classTitle": "car",
#     "tags": []
# }
property obj_class

ObjClass of the current VideoObject.

Returns

ObjClass object

Return type

ObjClass

Usage example
obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)
obj_car_json = video_obj_car.obj_class.to_json()
print(obj_car_json)
# Output: {
#     "title": "car",
#     "shape": "rectangle",
#     "color": "#8A0F7B",
#     "geometry_config": {},
#     "hotkey": ""
# }
key()[source]
property tags

VideoTagCollection of the current VideoObject.

Returns

VideoTagCollection object

Return type

VideoTagCollection

Usage example
# Create VideoTagCollection
meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
from supervisely_lib.video_annotation.video_tag import VideoTag
car_tag = VideoTag(meta_car, value='acura')
from supervisely_lib.video_annotation.video_tag_collection import VideoTagCollection
video_tags = VideoTagCollection([car_tag])

# Create VideoObject
obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car, video_tags)

# Get VideoTagCollection
tags = video_obj_car.tags
tags_json = tags.to_json()
print(tags_json)
# Output: [
#     {
#         "name": "car_tag",
#         "value": "acura",
#         "key": "4f82fbcab74c44259d7a0e29d604602e"
#     }
# ]
add_tag(tag: supervisely_lib.video_annotation.video_tag.VideoTag)supervisely_lib.video_annotation.video_object.VideoObject[source]

Adds VideoTag to the current VideoObject.

Parameters

tag (VideoTag) – VideoTag to be added.

Returns

VideoObject object

Return type

VideoObject

Usage example
# Create VideoObject
obj_class_car = sly.ObjClass('car', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)

# Create VideoTag
meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
from supervisely_lib.video_annotation.video_tag import VideoTag
car_tag = VideoTag(meta_car, value='acura')

# Add VideoTag
new_obj_car = video_obj_car.add_tag(car_tag)
new_obj_car_json = new_obj_car.to_json()
print(new_obj_car_json)
# Output: {
#     "key": "1ab52285ee634c93b724fa655b785eae",
#     "classTitle": "car",
#     "tags": [
#         {
#             "name": "car_tag",
#             "value": "acura",
#             "key": "d9e52b275e074c538f162a6d679aed9e"
#         }
#     ]
# }
add_tags(tags: List[supervisely_lib.video_annotation.video_tag.VideoTag])supervisely_lib.video_annotation.video_object.VideoObject[source]

Adds VideoTags to the current VideoObject.

Parameters

tag (List[VideoTag]) – List of VideoTags to be added.

Returns

VideoObject object

Return type

VideoObject

Usage example
# Create VideoObject
obj_class_vehicle = sly.ObjClass('vehicle', sly.Rectangle)
video_obj_vehicle = sly.VideoObject(obj_class_vehicle)

# Create VideoTags
from supervisely_lib.video_annotation.video_tag import VideoTag
meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
car_tag = VideoTag(meta_car, value='acura')
meta_bus = sly.TagMeta('bus_tag', sly.TagValueType.ANY_STRING)
bus_tag = VideoTag(meta_bus, value='volvo')

# Add VideoTags
new_obj_vehicle = video_obj_vehicle.add_tags([car_tag, bus_tag])
new_obj_vehicle_json = new_obj_vehicle.to_json()
print(new_obj_vehicle_json)
# Output: {
#     "key": "94055c5e8cb146368f627fc608fb6b44",
#     "classTitle": "vehicle",
#     "tags": [
#         {
#             "name": "car_tag",
#             "value": "acura",
#             "key": "6679f47c96734565919fbffc278532a1"
#         },
#         {
#             "name": "bus_tag",
#             "value": "volvo",
#             "key": "d0a60dc929de491a85a09fea59adb818"
#         }
#     ]
# }
to_json(key_id_map: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None) → dict[source]

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

Parameters

key_id_map (KeyIdMap, optional) – KeyIdMap object.

Returns

Json format as a dict

Return type

dict

Usage example
obj_class_car = sly.ObjClass('vehicle', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)

obj_car_json = video_obj_car.to_json()
print(obj_car_json)
# Output: {
#     "key": "ce26e77a45bc45e88e3e17da1672d01f",
#     "classTitle": "vehicle",
#     "tags": []
# }
classmethod from_json(data: dict, project_meta: supervisely_lib.project.project_meta.ProjectMeta, key_id_map: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = None)supervisely_lib.video_annotation.video_object.VideoObject[source]

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

Parameters
Raises

RuntimeError, if object class name is not found in the given project meta

Returns

VideoObject object

Return type

VideoObject

Usage example
obj_car_json = {
    "classTitle": "vehicle",
    "tags": []
}
obj_class_car = sly.ObjClass('vehicle', sly.Rectangle)
obj_collection = sly.ObjClassCollection([obj_class_car])
meta = sly.ProjectMeta(obj_classes=obj_collection)

video_obj_from_json = sly.VideoObject.from_json(obj_car_json, meta)
clone(obj_class: Optional[supervisely_lib.annotation.obj_class.ObjClass] = None, tags: Optional[supervisely_lib.video_annotation.video_tag_collection.VideoTagCollection] = None, key: Optional[supervisely_lib.video_annotation.key_id_map.KeyIdMap] = 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_object.VideoObject[source]

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

Parameters
  • obj_class (ObjClass, optional) – VideoObject class.

  • tags (VideoTagCollection, optional) – VideoObject tags.

  • key (KeyIdMap, optional) – KeyIdMap object.

  • class_id (int, optional) – ID of ObjClass to which VideoObject belongs.

  • labeler_login (str, optional) – Login of the user who created VideoObject.

  • updated_at (str, optional) – Date and Time when VideoObject 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 VideoObject was created. Date Format is the same as in “updated_at” parameter.

Returns

VideoObject object

Return type

VideoObject

Usage example
obj_class_car = sly.ObjClass('vehicle', sly.Rectangle)
video_obj_car = sly.VideoObject(obj_class_car)

# New ObjClass to clone
obj_class_bus = sly.ObjClass('bus', sly.Rectangle)

# New VideoTagCollection to clone
from supervisely_lib.video_annotation.video_tag import VideoTag
meta_car = sly.TagMeta('car_tag', sly.TagValueType.ANY_STRING)
car_tag = VideoTag(meta_car, value='acura')
from supervisely_lib.video_annotation.video_tag_collection import VideoTagCollection
tags = VideoTagCollection([car_tag])
# Clone
new_obj_vehicle = video_obj_car.clone(obj_class=obj_class_bus, tags=tags)
new_obj_vehicle_json = new_obj_vehicle.to_json()
print(new_obj_vehicle_json)
# Output: {
#     "key": "39ae5b9ce1ca405c9f53544374b3f5be",
#     "classTitle": "bus",
#     "tags": [
#         {
#             "name": "car_tag",
#             "value": "acura",
#             "key": "3119b6e38fe24fe7a220e881154fd9ba"
#         }
#     ]
# }