Frame¶
-
class Frame(index, figures=
None)[source]¶ Bases:
KeyObjectSingle frame in a video annotation; holds figures at a given index. Immutable.
- Parameters:
- Usage Example:
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) print(frame.to_json()) # Output: { # "index": 7, # "figures": [ # { # "key": "39f3eb15791f4c72b7cdb98c17b3f0f1", # "objectKey": "319814af474941a98ca208c3fad5ed81", # "geometryType": "rectangle", # "geometry": { # "points": { # "exterior": [ # [ # 0, # 0 # ], # [ # 100, # 100 # ] # ], # "interior": [] # } # } # } # ] # }
Methods
Makes a copy of Frame with new fields, if fields are given, otherwise it will use fields of the original Frame.
Convert a json dict to Frame.
Get Frame key (index) value.
Convert the Frame to a json dict.
Checks if image with given size contains a figure.
Attributes
Frame figures.
Frame index.
- figure_type¶
alias of
VideoFigure
-
classmethod from_json(data, objects, frames_count=
None, key_id_map=None)[source]¶ Convert a json dict to Frame. Read more about Supervisely format.
- Parameters:
- Raises:
ValueError – if frame index < 0 and if frame index > number of frames in video
- Returns:
Frameobject- Return type:
- Usage Example:
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) frame_json = frame.to_json() video_obj_coll = sly.VideoObjectCollection([object_car]) frame_car = sly.Frame.from_json(frame_json, video_obj_coll)
-
clone(index=
None, figures=None)[source]¶ Makes a copy of Frame with new fields, if fields are given, otherwise it will use fields of the original Frame.
- Parameters:
- Returns:
Frame object.
- Return type:
- Usage Example:
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) # Remember that Frame object is immutable, and we need to assign new instance of Frame to a new variable new_frame = frame.clone(index=100, figures=[]) print(new_frame.to_json()) # Output: { # "index": 100, # "figures": [] # }
- key()[source]¶
Get Frame key (index) value.
- Returns:
Frame key (index) value
- Return type:
- Usage Example:
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) print(frame.key()) # Output: 7
-
to_json(key_id_map=
None)[source]¶ Convert the Frame to a json dict. Read more about Supervisely format.
- Parameters:
- key_id_map=
None¶ KeyIdMap object.
- key_id_map=
- Returns:
Json format as a dict
- Return type:
Dict
- Usage Example:
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) frame_json = frame.to_json() print(frame_json) # Output: { # "index": 7, # "figures": [ # { # "key": "39f3eb15791f4c72b7cdb98c17b3f0f1", # "objectKey": "319814af474941a98ca208c3fad5ed81", # "geometryType": "rectangle", # "geometry": { # "points": { # "exterior": [ # [ # 0, # 0 # ], # [ # 100, # 100 # ] # ], # "interior": [] # } # } # } # ] # }
-
validate_figures_bounds(img_size=
None)[source]¶ Checks if image with given size contains a figure.
:raises
OutOfImageBoundsException: if figure is out of image bounds :returns: None :rtype: None- Usage Example:
import supervisely as sly frame_index = 7 geometry = sly.Rectangle(0, 0, 100, 100) class_car = sly.ObjClass('car', sly.Rectangle) object_car = sly.VideoObject(class_car) figure_car = sly.VideoFigure(object_car, geometry, frame_index) frame = sly.Frame(frame_index, figures=[figure_car]) image_size = (20, 200) frame.validate_figures_bounds(image_size) # raise OutOfImageBoundsException("Figure is out of image bounds")
- property figures : list[supervisely.video_annotation.video_figure.VideoFigure]¶
Frame figures.
- Returns:
List of figures on Frame.
- Return type:
List[
VideoFigure]- Usage Example:
frame_figures = frame.figures