Skip to content

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:

python
color_detection = ColorDetection(0)
# When there are multiple instances
color_detection_1 = ColorDetection(1)

Parameters ​

NameKindDescriptionRange / TypeDefault
indexDropdown optionInstance number (starting from 0)Integer 0 or greater0

Select the camera device ​

Sets the camera to use for color detection.

device

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionCamera device nameSystem camera label-

Python ​

python
color_detection = ColorDetection(0)

color_detection.device('')

Register a color ​

Adds a color to be recognized by color detection.

register_color

Parameters ​

NameKindDescriptionRange / TypeDefault
colorDropdown optionColor nameblack, red, yellow, green, cyan, blue, magenta, white-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

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.

delete_color

Parameters ​

NameKindDescriptionRange / TypeDefault
colorDropdown optionColor nameblack, red, yellow, green, cyan, blue, magenta, white-
waitCheckboxWhether to wait for completionTRUE / FALSETRUE

Python ​

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.

area_condition

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Area condition valueReal number 0 or greater-

Python ​

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.

detect_once

Parameters ​

(none)

Python ​

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.

detect_continuous

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionActionstart, stop-

Python ​

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.

display

Parameters ​

NameKindDescriptionRange / TypeDefault
onDropdown optionDisplay ON / OFFshow (on=True), hide (off=False)TRUE

Python ​

python
color_detection = ColorDetection(0)

color_detection.display(True)
color_detection.display(False)

Color information ​

Returns the position/size values of the specified color.

color_data

Parameters ​

NameKindDescriptionRange / TypeDefault
colorDropdown optionColor nameblack, red, yellow, green, cyan, blue, magenta, white-
posDropdown optionKind of coordinate/sizex, y, min_x, max_x, min_y, max_y, width, height, area-

Python ​

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

color_detected

Parameters ​

NameKindDescriptionRange / TypeDefault
colorDropdown optionColor nameblack, red, yellow, green, cyan, blue, magenta, white-

Python ​

python
color_detection = ColorDetection(0)

color_detection.color_detected('red')