Color
Color¶
Represents a color in RGB format.
Attributes:
Name | Type | Description |
---|---|---|
r |
int
|
Red channel. |
g |
int
|
Green channel. |
b |
int
|
Blue channel. |
Source code in supervision/draw/color.py
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
as_bgr()
¶
Returns the color as a BGR tuple.
Returns:
Type | Description |
---|---|
Tuple[int, int, int]
|
Tuple[int, int, int]: BGR tuple. |
Example
>>> color.as_bgr()
(255, 0, 255)
Source code in supervision/draw/color.py
104 105 106 107 108 109 110 111 112 113 114 115 116 117 |
|
as_hex()
¶
Converts the Color instance to a hex string.
Returns:
Name | Type | Description |
---|---|---|
str |
str
|
The hexadecimal color string. |
Example
>>> Color(r=255, g=0, b=255).as_hex()
'#ff00ff'
Source code in supervision/draw/color.py
74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
|
as_rgb()
¶
Returns the color as an RGB tuple.
Returns:
Type | Description |
---|---|
Tuple[int, int, int]
|
Tuple[int, int, int]: RGB tuple. |
Example
>>> color.as_rgb()
(255, 0, 255)
Source code in supervision/draw/color.py
89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
|
from_hex(color_hex)
classmethod
¶
Create a Color instance from a hex string.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_hex |
str
|
Hex string of the color. |
required |
Returns:
Name | Type | Description |
---|---|---|
Color |
Color
|
Instance representing the color. |
Example
>>> Color.from_hex('#ff00ff')
Color(r=255, g=0, b=255)
Source code in supervision/draw/color.py
50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
|
ColorPalette¶
Source code in supervision/draw/color.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
by_idx(idx)
¶
Return the color at a given index in the palette.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
idx |
int
|
Index of the color in the palette. |
required |
Returns:
Name | Type | Description |
---|---|---|
Color |
Color
|
Color at the given index. |
Example
>>> color_palette.by_idx(1)
Color(r=0, g=255, b=0)
Source code in supervision/draw/color.py
180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 |
|
default()
classmethod
¶
Returns a default color palette.
Returns:
Name | Type | Description |
---|---|---|
ColorPalette |
ColorPalette
|
A ColorPalette instance with default colors. |
Example
>>> ColorPalette.default()
ColorPalette(colors=[Color(r=255, g=0, b=0), Color(r=0, g=255, b=0), ...])
Source code in supervision/draw/color.py
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 |
|
from_hex(color_hex_list)
classmethod
¶
Create a ColorPalette instance from a list of hex strings.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
color_hex_list |
List[str]
|
List of color hex strings. |
required |
Returns:
Name | Type | Description |
---|---|---|
ColorPalette |
ColorPalette
|
A ColorPalette instance. |
Example
>>> ColorPalette.from_hex(['#ff0000', '#00ff00', '#0000ff'])
ColorPalette(colors=[Color(r=255, g=0, b=0), Color(r=0, g=255, b=0), ...])
Source code in supervision/draw/color.py
160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 |
|