ObjClass¶
- class ObjClass[source]¶
Bases:
supervisely.collection.key_indexed_collection.KeyObject
,supervisely.io.json.JsonSerializable
General information about
Label
.ObjClass
object is immutable.- Parameters
- name : str
Class name.
- geometry_type : dict, optional
Defines the shape of ObjClass:
Bitmap
,Cuboid
,Graph
,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.
- Raises
ValueError
, if color is not list or tuple, or doesn’t have exactly 3 values- Usage example
import supervisely as sly # Simple ObjClass example class_lemon = sly.ObjClass('lemon', sly.Rectangle) # More complex ObjClass example 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.
Used as a key in ObjClassCollection (like key in dict)
Convert the ObjClass to a json dict.
Attributes
[R,G,B]
color.Description.
geometry_config
- rtype
Type of the geometry that is associated with ObjClass.
Hotkey for ObjClass in annotation tool UI..
Name.
Class ID in Supervisely server.
-
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
- 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()
- classmethod from_json(data)[source]¶
Convert a json dict to ObjClass. Read more about Supervisely format.
- key()[source]¶
Used as a key in ObjClassCollection (like key in dict)
- Returns
string name of the ObjectClass
- Return type
Str
- 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¶
[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¶
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¶
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¶
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'
- property name¶
Name.
- Returns
Name
- Return type
- Usage example
class_lemon = sly.ObjClass('lemon', sly.Rectangle) print(class_lemon.name) # Output: 'lemon'