Built-in Tracking Models
Import KOI 2 Library
from future import *
from koi2 import KOI2
Serial Initialization
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:
data: The type of data to return.
0
X coordinates
1
Y coordinates
2
Width of road sign
3
Height of road sign
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()
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:
data: The type of data to return.
0
X coordinates
1
Y coordinates
2
Width of item
3
Height of item
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()
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:
data: The type of data to return.
0
X coordinates
1
Y coordinates
2
Width of alphabet
3
Height of alphabet
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()
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:
data: The type of data to return.
0
X coordinates
1
Y coordinates
2
Width of number
3
Height of number
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()
Last updated