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

clone

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

from_json

Convert a json dict to ObjClass.

get_header_ptable

get_row_ptable

key

Used as a key in ObjClassCollection (like key in dict)

to_json

Convert the ObjClass to a json dict.

Attributes

color

[R,G,B] color.

description

Description.

geometry_config

rtype

Dict

geometry_type

Type of the geometry that is associated with ObjClass.

hotkey

Hotkey for ObjClass in annotation tool UI..

name

Name.

sly_id

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

ObjClass

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.

Parameters
data : dict

ObjClass in json format as a dict.

Returns

ObjClass object

Return type

ObjClass

Usage example
import supervisely as sly

data = {
    "title": "lemon",
    "shape": "rectangle",
    "color": "#0F6E8A",
    "hotkey": "Q"
}

class_lemon = sly.ObjClass.from_json(data)
classmethod get_header_ptable()[source]
get_row_ptable()[source]
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

dict

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

str

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

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

str

Usage example
class_lemon = sly.ObjClass('lemon', sly.Rectangle, hotkey='M')
print(class_lemon.hotkey)
# Output: 'M'
property name

Name.

Returns

Name

Return type

str

Usage example
class_lemon = sly.ObjClass('lemon', sly.Rectangle)
print(class_lemon.name)
# Output: 'lemon'
property sly_id

Class ID in Supervisely server.

return

ID

rtype

int

Usage example
class_lemon = sly.ObjClass('lemon', sly.Rectangle, sly_id=38584)
print(class_lemon.sly_id)
# Output: 38584
Return type

int