ObjClass¶
-
class ObjClass(name, geometry_type, color=
None, geometry_config=None, sly_id=None, hotkey=None, description=None)[source]¶ Bases:
KeyObject,JsonSerializableObject class: name, geometry type (Rectangle, Polygon, etc.), color. Immutable.
- Parameters:
- name : str¶
Class name (e.g. ‘car’, ‘person’).
- geometry_type : type¶
Geometry type: Rectangle, Polygon, Bitmap, Point, Polyline, Cuboid, GraphNodes, etc.
- color : List[int, int, int], optional¶
RGB color [R, G, B]. Random color if not provided.
- geometry_config : dict, optional¶
Extra geometry settings (e.g. KeypointsTemplate for GraphNodes).
- sly_id : int, optional¶
Server-side class ID.
- hotkey : str, optional¶
Hotkey in annotation UI.
- description : str, optional¶
Class description.
- Raises:
ValueError – If color has invalid format or GraphNodes has no geometry_config.
- Usage Example:
import supervisely as sly class_lemon = sly.ObjClass('lemon', sly.Rectangle) class_cucumber = sly.ObjClass('cucumber', sly.Bitmap, color=[128, 0, 255], hotkey='d')
Methods
Makes a copy of ObjClass with new fields, if fields are given, otherwise it will use fields of the original ObjClass.
Convert a json dict to ObjClass.
get_header_ptable
get_row_ptable
Used as a key in ObjClassCollection (like key in dict)
Convert the ObjClass to a json dict.
Attributes
[R,G,B]color.Description.
geometry_configType of the geometry that is associated with ObjClass.
Hotkey for ObjClass in annotation tool UI..
Name.
Class ID in Supervisely server.
- classmethod from_json(data)[source]¶
Convert a json dict to ObjClass. Read more about Supervisely format.
-
clone(name=
None, geometry_type=None, color=None, geometry_config=None, sly_id=None, hotkey=None, description=None)[source]¶ Makes a copy of ObjClass with new fields, if fields are given, otherwise it will use fields of the original ObjClass.
- Parameters:
- name : str¶
Class name.
- geometry_type : type¶
Defines the shape of ObjClass:
Bitmap>,Cuboid>,Point>,Polygon>,Polyline>,Rectangle>.- color : List[int, int, int], optional¶
[R, G, B], generates random color by default.- geometry_config : dict, optional¶
Additional settings of the geometry.
- sly_id : int, optional¶
ID in Supervisely server.
- hotkey : str, optional¶
Hotkey for ObjClass in annotation tool UI.
- description : str, optional¶
Description of the class.
- Returns:
New instance of ObjClass object
- Return type:
- Usage Example:
import supervisely as sly class_lemon = sly.ObjClass('lemon', sly.Rectangle) # Let's clone our ObjClass, but with different name # Remember that ObjClass object is immutable, and we need to assign new instance of ObjClass to a new variable clone_lemon_1 = class_lemon.clone(name="lemon clone") # Let's clone our ObjClass, but with different color and hotkey # Remember that ObjClass object is immutable, and we need to assign new instance of ObjClass to a new variable clone_lemon_2 = class_lemon.clone(color=[128, 0, 64], hotkey='Q') # Let's clone our ObjClass without new fields clone_lemon_3 = class_lemon.clone()
- key()[source]¶
Used as a key in ObjClassCollection (like key in dict)
- Returns:
string name of the ObjectClass
- Return type:
- to_json()[source]¶
Convert the ObjClass to a json dict. Read more about Supervisely format.
- Returns:
Json format as a dict
- Return type:
- Usage Example:
import supervisely as sly class_lemon = sly.ObjClass('lemon', sly.Rectangle) lemon_json = class_lemon.to_json() print(lemon_json) # Output: { # "title": "lemon", # "shape": "rectangle", # "color": "#8A2F0F", # "geometry_config": {}, # "hotkey": "" # }
- property color : list[int, int, int]¶
[R,G,B]color.- Returns:
Color
- Return type:
List[int, int, int]- Usage Example:
class_lemon = sly.ObjClass('lemon', sly.Rectangle, color=[255,120,0]) print(class_lemon.color) # Output: [255,120,0]
- property description : str¶
Description.
- Returns:
Description
- Return type:
- Usage Example:
class_lemon = sly.ObjClass('lemon', sly.Rectangle) print(class_lemon.description) # Output: 'lemon class description'
- property geometry_type : supervisely.geometry.geometry.Geometry¶
Type of the geometry that is associated with ObjClass.
- Returns:
Geometry type
- Return type:
- Usage Example:
class_lemon = sly.ObjClass('lemon', sly.Rectangle) print(class_lemon.geometry_type) # Output: <class 'supervisely.geometry.rectangle.Rectangle'> class_kiwi = sly.ObjClass('kiwi', sly.Bitmap) print(class_kiwi.geometry_type) # Output: <class 'supervisely.geometry.bitmap.Bitmap'>
- property hotkey : str¶
Hotkey for ObjClass in annotation tool UI..
- Returns:
Hotkey
- Return type:
- Usage Example:
class_lemon = sly.ObjClass('lemon', sly.Rectangle, hotkey='M') print(class_lemon.hotkey) # Output: 'M'