Programming with MicroPython: KOI

Import KOI Library

Import KOI library to make use of its functions.

from futureKOI import KOI

KOI Basic Operations

Initiate KOI

koi = KOI(tx='P2',rx='P12',id=1)

Initiates the KOI port.

  • tx: Tx Pin, use P2 for Robotbit Edu.

  • rx: Rx Pin, use P12 for Robotbit Edu.

Set KOI Camera Orientation

# available modes
# 0,2

koi.screen_mode(mode, cmd='K6')

Sets the KOI camera orientation.

  • mode: 0 for front, 2 for back

Display text

Displays a text on the KOI screen.

  • x: X coordinate of the text.

  • y: Y coordinate of the text.

  • delay: Duration of the text in ms.

  • text: The string to be displayed.

KOI Screen Capture

Captures the screen and save to SD card.

  • pic: Filename on the SD card in jpg format.

KOI Displays JPG

Displays a jpg on the screen.

  • pic: Filename on the SD card in jpg format.

Face Detection

Load Face Yolo

Loads the face yolo model.

Single Face Detection

Runs the single face detection.

Obtain Face Coordinates

Returns the X or Y coordinate of the face detected.

Multi Face Detection

Runs the multi face detection.

Obtain Number of Faces

Returns the number of faces detected.

Face Detection Sample Program

Machine Learning Image Classifier

Initiate Image Classifier

Starts image classifier mode.

Save the Classifier Model

Saves the model to the SD Card.

  • model: The filename on the SD card.

Load a Classifier Model

Loads the model from the SD Card.

  • model: The filename on the SD card.

Classifier Add Tag

Add an image tag.

  • tag: Name of the tag.

Run Image Classifier

Returns the tag for the classified object.

KOI Classifier Model Training Sample Program

KOI Image Classification Sample Program

Colour Blob and Line Tracking

Calibrate a Colour to Track

Calibrates a colour to track.

  • name: The name for this colour.

Tracks a Colour Blob

Returns a list containing the values of the colour blob.

  • name: the name of the colour to track.

Obtain Colour Blob Values

Returns the specific value of the colour blob.

Blob Detection Sample Program

Tracks a line

Returns a list containing the values of the line.

  • name: the name of the colour to track.

Obtain Line Values

Returns the specific value of the line.

Line Detection Sample Program

Shape Detection

Circle Detection

Runs the circle detection.

  • threshold: The threshold for circle, typical value is about 2000, adjust to achieve best results.

Obtain Circle Values

Returns the specific value of the circle.

Rectangle Detection

Runs the rectangle detection.

  • threshold: The threshold for rectangle, typical value is about 1000, adjust to achieve best results.

Obtain Rectangle Values

Returns the specific value of the rectangle.

Shape Detection Sample Program

Code Scanner

QR Code Scanner

Returns the QR Code data.

Barcode Scanner

Returns the Barcode data.

Apriltag Scanner

Runs the scanner for Apriltag.

Obtains Apriltag data

Returns the specific data of the Apriltag.

Code Scanner Sample Program

Wifi Connection

Connect to Wifi

Connects to a Wifi network.

  • router: The SSID.

  • pwd: The password.

Displays IP Address

Displays the IP Address.

BaiduAI

BaiduAI Face Recognition

Returns a list of values from the BaiduAI Face Recognition.

BaiduAI Face Token

Returns the face token.

BaiduAI Add Face to Group

Adds the face token to a group.

  • face_token: The token to be added.

  • groupName: The group name.

  • faceName: The name of the person.

BaiduAI Search Face in Group

Searches the face in a group and returns the person name.

  • face_token: The token to be searched.

  • groupName: The group name.

BaiduAi Text to Speech

Generates a speech using BaiduAI.

-text: The text to be spoken.

Wifi and Baidu TTS Sample Program

Audio

Record Wav File

Record and saves the wav file to the SD card.

  • name: The file name in wav format.

Play Wav File

Plays a wav file from the SD card.

  • name: The file name in wav format.

Calibrate Ambient Noise

Calibrates the ambient noise for speech recognition.

Speech Recognition Add Tag

Adds a speech tag.

  • tag: The tag name.

Get Speech Recognition Tag

Runs the speech recognition and returns the tag.

Save Speech Model

Saves the speech model to the SD card.

  • file: The filename.

Load Speech Model

Loads a speech model.

  • file: The filename.

Speech Recognition Training Sample Program

Speech Recognition Sample Program

Miscellaneous

Reset KOI

Resets the KOI.

Stop Classifier and Face Yolo

Stops the KPU from running Classifier and Face Yolo.

Last updated