Skip to content

Object Detection ​

Instance declaration ​

When you add an Object Detection block to the workspace, the following instance declaration is automatically inserted into the Python code:

python
object_detection = ObjectDetection(0)
# When there are multiple instances
object_detection_1 = ObjectDetection(1)

Parameters ​

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

Select the camera device ​

Sets the camera to use for object detection.

device

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionCamera device nameSystem camera label-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.device('')

Load the model ​

Loads the trained object model. This step is required in order to use the features of the 'Object Detection' module.

load_model

Parameters ​

NameKindDescriptionRange / TypeDefault
waitCheckboxWhether to wait for loading to completeTRUE / FALSETRUE

Python ​

python
object_detection = ObjectDetection(0)

object_detection.load_model(wait=True)

Set the maximum object count ​

Sets the maximum number of objects that can be found. The object count ranges from 0 to 10.

max_objects

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Maximum object countInteger 0 to 10-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.max_objects(5)

Set the confidence threshold ​

Sets the minimum probability (confidence) for object detection. Only results whose probability (confidence) is at or above this value are shown on screen. The probability (confidence) ranges from 0 to 1.

confidence_threshold

Parameters ​

NameKindDescriptionRange / TypeDefault
dataInput (block)Confidence thresholdReal number 0 to 1-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.confidence_threshold(0.5)

Detect once ​

Finds the objects currently on screen and marks them just once.

detect_once

Parameters ​

(none)

Python ​

python
object_detection = ObjectDetection(0)

object_detection.detect_once()

Start / stop continuous detection ​

Keeps following the objects currently on screen and marks them on the screen.

detect_continuous

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionActionstart, stop-

Python ​

python
object_detection = ObjectDetection(0)

# unit = "start"
object_detection.detect_continuous()
# unit = "stop"
object_detection.stop()

Show the detection result ​

Decides whether or not to show the object detection result on the camera screen.

display

Parameters ​

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

Python ​

python
object_detection = ObjectDetection(0)

object_detection.display(True)
object_detection.display(False)

Object position information ​

Returns the position/size values of the specified object.

object_data

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionObject name80 object classes ('person', 'bicycle', 'car', 'motorcycle', 'airplane', 'bus', 'cat', 'dog', 'apple', 'cup', 'laptop', 'cell_phone', and so on)-
posDropdown optionCoordinatex, y-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object('person', 'x')
object_detection.object('bicycle', 'y')

Object rectangle information ​

Returns the position/size values of the rectangle around the specified object region.

object_square

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionObject name80 object classes-
posDropdown optionRectangle informationmin_x, max_x, min_y, max_y, width, height, area-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object('person', 'width')
object_detection.object('car', 'area')

Distance between two objects ​

Returns the distance between two object classes.

object_distance

Parameters ​

NameKindDescriptionRange / TypeDefault
unit1Dropdown optionFirst object name80 object classes-
unit2Dropdown optionSecond object name80 object classes-
typeDropdown optionKind of distancedistance (omitted or None), horizontal distance (horizontal), vertical distance (vertical)None

Python ​

python
object_detection = ObjectDetection(0)

object_detection.get_distance('person', 'bicycle')  # distance
object_detection.get_distance('person', 'car', 'horizontal')  # horizontal distance

Object confidence ​

The probability (confidence) that the selected object is correct

object_confidence

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionObject name80 object classes-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object_confidence('person')

Model state ​

Returns the loading state of the object model.
It returns 0 if it has not been loaded yet, 1 while it is loading, and 2 once loading is complete.

model_state

Parameters ​

(none)

Python ​

python
object_detection = ObjectDetection(0)

object_detection.model_state()

Whether an object was detected ​

Whether an object was found

detected

Parameters ​

(none)

Python ​

python
object_detection = ObjectDetection(0)

object_detection.detected()

Was a particular object detected? ​

Whether the selected object was found

object_detected

Parameters ​

NameKindDescriptionRange / TypeDefault
unitDropdown optionObject name80 object classes-

Python ​

python
object_detection = ObjectDetection(0)

object_detection.object_detected('person')