> For the complete documentation index, see [llms.txt](https://help.trikset.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://help.trikset.com/en/trik/programming-code/object-brick/class-objectsensor.md).

# Class «objectSensor»

{% hint style="info" %}
This article is automatically translated from Russian by Google Translator.
{% endhint %}

Camera in object sensor mode. Captures a contrasting object in the center of the frame and returns its coordinates and size in the frame.

| Method                                                                        | Description                                                                                                                                                                                                      |
| ----------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [detect](/en/trik/programming-code/object-brick/class-objectsensor.md#detect) | Detects the dominant color in the center of the frame and remembers it as the color of the object.                                                                                                               |
| [init](/en/trik/programming-code/object-brick/class-objectsensor.md#init)     | Switches the camcorder on and initializes it in object sensor mode.                                                                                                                                              |
| [read](/en/trik/programming-code/object-brick/class-objectsensor.md#read)     | Returns an array with the X coordinate of the object center relative to the center of the frame, the Y coordinate of the object center relative to the center of the frame, and the relative size of the object. |
| [stop](/en/trik/programming-code/object-brick/class-objectsensor.md#stop)     | Turns off the camera and stops the sensor.                                                                                                                                                                       |

## detect

Detects the dominant color in the center of the frame and remembers it as the color of the object. After that, the "[read](/en/trik/programming-code/object-brick/class-objectsensor.md#read)" method starts to return data for the object.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
brick.objectSensor().detect();
```

{% endtab %}

{% tab title="Python" %}

```
brick.objectSensor().detect();
```

{% endtab %}
{% endtabs %}

## init

Switches the camcorder on and initializes it in object sensor mode. The boolean parameter determines whether to display the image from the camera (`true` — display).

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
brick.objectSensor().init(true);
```

{% endtab %}

{% tab title="Python" %}

```
brick.objectSensor().init(True);
```

{% endtab %}
{% endtabs %}

The boolean parameter defines whether to display the image from the camera:

* `true` — output,
* `false` — don't output.

## read

Returns an array that contains the following data in its cells:

* In the zero cell, the X-axis coordinate of the object center relative to the center of the frame (-100 to 100, -100 is the center of the object on the edge of the frame on the left);
* The Y-coordinate of the object's center relative to the frame center (from -100 to 100, -100 is the center of the object on the frame edge at the top);&#x20;
* The second cell is the relative size of the object, a number from 0 to 100 (100 - the object occupies almost the entire frame, 0 - the object is not on the frame).

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
brick.objectSensor().read();
```

{% endtab %}

{% tab title="Python" %}

```
brick.objectSensor().read();
```

{% endtab %}
{% endtabs %}

## stop

Turns off the camera and stops the sensor.

#### Syntax

{% tabs %}
{% tab title="JavaScript" %}

```javascript
brick.objectSensor().stop();
```

{% endtab %}

{% tab title="Python" %}

```
brick.objectSensor().stop();
```

{% endtab %}
{% endtabs %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://help.trikset.com/en/trik/programming-code/object-brick/class-objectsensor.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
