Color Detection
Instance declaration
When you add a Color Detection block to the workspace, the following instance declaration is automatically inserted into the Python code:
color_detection = ColorDetection(0)
# When there are multiple instances
color_detection_1 = ColorDetection(1)Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| index | Dropdown option | Instance number (starting from 0) | Integer 0 or greater | 0 |
Select the camera device
Sets the camera to use for color detection.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Camera device name | System camera label | - |
Python
color_detection = ColorDetection(0)
color_detection.device('')Register a color
Adds a color to be recognized by color detection.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| color | Dropdown option | Color name | black, red, yellow, green, cyan, blue, magenta, white | - |
| wait | Checkbox | Whether to wait for completion | TRUE / FALSE | TRUE |
Python
color_detection = ColorDetection(0)
color_detection.register_color('red', wait=True)Delete a color
Deletes that color from the colors to be recognized by color detection.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| color | Dropdown option | Color name | black, red, yellow, green, cyan, blue, magenta, white | - |
| wait | Checkbox | Whether to wait for completion | TRUE / FALSE | TRUE |
Python
color_detection = ColorDetection(0)
color_detection.delete_color('blue', wait=True)Set the area condition
Sets the minimum size of the color region to recognize. Only regions whose area is at or above this value are shown on screen.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| data | Input (block) | Area condition value | Real number 0 or greater | - |
Python
color_detection = ColorDetection(0)
color_detection.area_condition(50)Detect once
Among the recognizable colors, finds the ones currently on screen and marks their regions just once.

Parameters
(none)
Python
color_detection = ColorDetection(0)
color_detection.detect_once()Start / stop continuous detection
Among the recognizable colors, keeps following the ones currently on screen and marks their regions on the screen.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| unit | Dropdown option | Action | start, stop | - |
Python
color_detection = ColorDetection(0)
# unit = "start"
color_detection.detect_continuous()
# unit = "stop"
color_detection.stop()Show the detection result
Decides whether or not to show the color detection result on the camera screen.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| on | Dropdown option | Display ON / OFF | show (on=True), hide (off=False) | TRUE |
Python
color_detection = ColorDetection(0)
color_detection.display(True)
color_detection.display(False)Color information
Returns the position/size values of the specified color.

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| color | Dropdown option | Color name | black, red, yellow, green, cyan, blue, magenta, white | - |
| pos | Dropdown option | Kind of coordinate/size | x, y, min_x, max_x, min_y, max_y, width, height, area | - |
Python
color_detection = ColorDetection(0)
color_detection.color('red', 'x')
color_detection.color('green', 'y')
color_detection.color('blue', 'area')Whether a particular color was detected
Whether the selected color was found

Parameters
| Name | Kind | Description | Range / Type | Default |
|---|---|---|---|---|
| color | Dropdown option | Color name | black, red, yellow, green, cyan, blue, magenta, white | - |
Python
color_detection = ColorDetection(0)
color_detection.color_detected('red')