ObjClass

class ObjClass(name, geometry_type, color=None, geometry_config=None, sly_id=None, hotkey=None, description=None)[source]

Bases: KeyObject, JsonSerializable

Object 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

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_header_ptable

get_row_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

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.

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]
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:

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()
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 : 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:

str

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:

Geometry

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:

str

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

Name.

Returns:

Name

Return type:

str

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

Class ID in Supervisely server.

returns:

ID

rtype:

int

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