> For the complete documentation index, see [llms.txt](https://sharinghub-eng.kittenbot.hk/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://sharinghub-eng.kittenbot.hk/airelated/ai-camera-koi-2/micropython-programming/built-in-tracking-models.md).

# Built-in Tracking Models

## Import KOI 2 Library

```python
from future import *
from koi2 import KOI2
```

## Serial Initialization

```python
koi = KOI2(tx, rx)
```

Initializes the serial connection to KOI.

Parameters:

tx: TX Pin, use P2 for Robotbit EDU

rx: RX Pin, use P12 for Robotbit EDU

## Select Road Sign Tracking Mode

```
koi.setModel(1)
```

Sets the KOI mode to Road Sign Tracking.

## Get Road Sign Coordinates

```
koi.xywh[0]
```

Returns coordinates for the detected road sign.

Parameters:&#x20;

data: The type of data to return.

<table><thead><tr><th width="324">data</th><th>Meaning</th></tr></thead><tbody><tr><td>0</td><td>X coordinates</td></tr><tr><td>1</td><td>Y coordinates</td></tr><tr><td>2</td><td>Width of road sign</td></tr><tr><td>3</td><td>Height of road sign</td></tr></tbody></table>

## Get Road Sign Name

```
koi.strVal
```

Returns the name of the road sign.

Values Returned: U-Turn, forward, left, right, limit-30, stop, tunnel

## Sample Code: Road Sign Tracking

```
from future import *
from koi2 import KOI2



koi = KOI2('P2', 'P12')
koi.setModel(1)
sleep(15)
koi.direction(2)
koi.mirror(0)
screen.sync = 0
while True:
  koi.read_from_uart()
  screen.fill((0, 0, 0))
  screen.text(koi.strVal,5,10,2,(255, 255, 255))
  screen.text(koi.xywh[0],5,30,2,(255, 255, 255))
  screen.text(koi.xywh[1],5,50,2,(255, 255, 255))
  screen.text(koi.xywh[2],5,70,2,(255, 255, 255))
  screen.text(koi.xywh[3],5,90,2,(255, 255, 255))
  screen.refresh()

```

{% file src="/files/e5e2BmT2KXtfNSKIBjxI" %}

## Select Common Items Tracking Mode

```
koi.setModel(2)
```

Sets the KOI mode to Common Items Tracking.

## Get Item Coordinates

```
koi.xywh[0]
```

Returns coordinates for the detected item.

Parameters:&#x20;

data: The type of data to return.

<table><thead><tr><th width="324">data</th><th>Meaning</th></tr></thead><tbody><tr><td>0</td><td>X coordinates</td></tr><tr><td>1</td><td>Y coordinates</td></tr><tr><td>2</td><td>Width of item</td></tr><tr><td>3</td><td>Height of item</td></tr></tbody></table>

## Get Item Name

```
koi.strVal
```

Returns the name of the item.

Values Returned: aeroplane, bicycle, bird, boat, bottle, bus, car, cat, chair, cow, diningtable, dog, horse, motorbike, person, pottedplant, sheep, sofa, train, tvmonitor

## Sample Code: Item Tracking

```
from future import *
from koi2 import KOI2



koi = KOI2('P2', 'P12')
koi.setModel(2)
sleep(15)
koi.direction(2)
koi.mirror(0)
screen.sync = 0
while True:
  koi.read_from_uart()
  screen.fill((0, 0, 0))
  screen.text(koi.strVal,5,10,2,(255, 255, 255))
  screen.text(koi.xywh[0],5,30,2,(255, 255, 255))
  screen.text(koi.xywh[1],5,50,2,(255, 255, 255))
  screen.text(koi.xywh[2],5,70,2,(255, 255, 255))
  screen.text(koi.xywh[3],5,90,2,(255, 255, 255))
  screen.refresh()

```

{% file src="/files/3g2LZuvXZc1wm5sGqoAS" %}

## Select Alphabets Tracking Mode

```
koi.setModel(6)
```

Sets the KOI mode to Alphabet Tracking.

## Get Alphabet Coordinates

```
koi.xywh[0]
```

Returns coordinates for the detected alphabet.

Parameters:&#x20;

data: The type of data to return.

<table><thead><tr><th width="324">data</th><th>Meaning</th></tr></thead><tbody><tr><td>0</td><td>X coordinates</td></tr><tr><td>1</td><td>Y coordinates</td></tr><tr><td>2</td><td>Width of alphabet</td></tr><tr><td>3</td><td>Height of alphabet</td></tr></tbody></table>

## Get Alphabet Name

```
koi.strVal
```

Returns the name of the alphabet.

Values Returned: A, B, C, D, E, F

## Sample Code: Alphabet Tracking

```
from future import *
from koi2 import KOI2



koi = KOI2('P2', 'P12')
koi.setModel(6)
sleep(15)
koi.direction(2)
koi.mirror(0)
screen.sync = 0
while True:
  koi.read_from_uart()
  screen.fill((0, 0, 0))
  screen.text(koi.strVal,5,10,2,(255, 255, 255))
  screen.text(koi.xywh[0],5,30,2,(255, 255, 255))
  screen.text(koi.xywh[1],5,50,2,(255, 255, 255))
  screen.text(koi.xywh[2],5,70,2,(255, 255, 255))
  screen.text(koi.xywh[3],5,90,2,(255, 255, 255))
  screen.refresh()

```

{% file src="/files/W9xWEQxn7FZZd11nOVZQ" %}

## Select Numbers Tracking Mode

```
koi.setModel(4)
```

Sets the KOI mode to Numbers Tracking.

## Get Number Coordinates

```
koi.xywh[0]
```

Returns coordinates for the detected number.

Parameters:&#x20;

data: The type of data to return.

<table><thead><tr><th width="324">data</th><th>Meaning</th></tr></thead><tbody><tr><td>0</td><td>X coordinates</td></tr><tr><td>1</td><td>Y coordinates</td></tr><tr><td>2</td><td>Width of number</td></tr><tr><td>3</td><td>Height of number</td></tr></tbody></table>

## Get Number Name

```
koi.numberVal
```

Returns the name of the number.

Values Returned: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

## Sample Code: Number Tracking

```
from future import *
from koi2 import KOI2



koi = KOI2('P2', 'P12')
koi.setModel(4)
sleep(15)
koi.direction(2)
koi.mirror(0)
screen.sync = 0
while True:
  koi.read_from_uart()
  screen.fill((0, 0, 0))
  screen.text(koi.numberVal,5,10,2,(255, 255, 255))
  screen.text(koi.xywh[0],5,30,2,(255, 255, 255))
  screen.text(koi.xywh[1],5,50,2,(255, 255, 255))
  screen.text(koi.xywh[2],5,70,2,(255, 255, 255))
  screen.text(koi.xywh[3],5,90,2,(255, 255, 255))
  screen.refresh()

```


---

# 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://sharinghub-eng.kittenbot.hk/airelated/ai-camera-koi-2/micropython-programming/built-in-tracking-models.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.
