aivision#
Initializing the aivision Class#
An AI Vision Sensor is created by using one of the following constructors:
The aivision(port)
constructor creates an aivision object in the specified port.
Parameter |
Description |
---|---|
|
A valid Smart Port that the AI Vision Sensor is connected to. |
// Create a new AI Vision Sensor "aiVision" with the aivision class.
aivision aiVision = aivision(PORT1);
The aivision(port, colors, codes)
constructor creates an AI Vision object.
Parameter |
Description |
---|---|
|
A valid Smart Port that the AI Vision Sensor is connected to. |
|
The name of one or more Colordesc objects. |
|
The name of one or more Codedesc objects. |
// Create a new Color Signature "Red" with the colordesc class.
aivision::colordesc Red = aivision::colordesc(1, 207, 19, 25, 10.00, 0.20);
// Create a new AI Vision Sensor "ai_vision" with the AiVision
// class, with the "Red' Colordesc.
aivision aiVision = aivision(PORT1, Red);
This aiVision
object and aiVision__Red
Colordesc object will be used in all subsequent examples throughout this API documentation when referring to AiVision class methods.
Class Methods#
takeSnapshot()#
This method is called in the following ways:
The takeSnapshot(id, type, count)
method takes the current snapshot visible to the AI Vision Sensor and detects the objects of a given signature, code, or signature id.
Parameters |
Description |
---|---|
id |
The id of the object to look for. |
type |
A valid ObjectType. |
count |
The maximum number of objects to obtain. The default is 8. |
Returns: An integer representing the number of objects found mathing the description passed as a parameter.
The takeSnapshot(desc, count)
method takes the current snapshot visible to the AI Vision Sensor and detects the objects of a given signature, code, or signature id.
Parameters |
Description |
---|---|
type |
|
count |
The maximum number of objects to obtain. The default is 8. |
Returns: An integer representing the number of objects found mathing the description passed as a parameter.
while (true){
// Take a snapshot of the red objects detected by
// the AI Vision Sensor.
aiVision.takeSnapshot(Red);
// Clear the screen/reset so that we can display
// new information.
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
// Print the largest detected object's CenterX
// coordinate to the Brain's screen.
Brain.Screen.print("Object Count: %d", aiVision.objectCount);
// Wait 0.5 seconds before repeating the loop and
// taking a new snapshot.
wait(0.5, seconds);
}
largestObject#
The largestObject
property contains the largest object detected by the AI Vision Sensor in the latest snapshot.
The object contained in largestObject
has fifteen properties that can be accessed to obtain various information about the detected object.
AI Vision Object Properties |
Description |
---|---|
|
An integer representing the object’s ID. |
|
An objectType representing the object’s type. |
|
An integer representing the top left x position of the object. |
|
An integer representing the top left y position of the object. |
|
An integer representing the center x position of the object. |
|
An integer representing the center y position of the object. |
|
An integer representing the object’s width in pixels. |
|
An integer representing the object’s height in pixels. |
|
A float representing the object’s angle in pixels. Note: This is only usable with Color Codes/ |
|
If the AI Vision camera detects the object. |
|
A |
|
A char representing the class name of the object. |
|
A color representing the object’s color. |
|
The confidence score for this object ranges from 0% - 100%. It represents how confident the AI Vision Sensor is in accurately identifying the object. |
|
An integer representing the area of the object`s bounding box in pixels. |
Returns: An object or None if it does not exist.
while (true){
// Take a snapshot of the red objects detected by
// the AI Vision Sensor.
aiVision.takeSnapshot(Red);
// Clear the screen/reset so that we can display
// new information.
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
// Print the largest detected object's CenterX
// coordinate to the Brain's screen.
Brain.Screen.print("Center X: %d", aiVision.largestObject.centerX);
// Wait 0.5 seconds before repeating the loop and
// taking a new snapshot.
wait(0.5, seconds);
}
objectCount#
The objectCount
property contains the number of objects found in the most recent snapshot.
Returns: An integer representing the number of objects found in the most recent snapshot.
while (true){
// Take a snapshot of the red objects detected by
// the AI Vision Sensor.
aiVision.takeSnapshot(Red);
// Clear the screen/reset so that we can display
// new information.
Brain.Screen.clearScreen();
Brain.Screen.setCursor(1, 1);
// Print the largest detected object's CenterX
// coordinate to the Brain's screen.
Brain.Screen.print("Object Count: %d", aiVision.objectCount);
// Wait 0.5 seconds before repeating the loop and
// taking a new snapshot.
wait(0.5, seconds);
}
tagDetection()#
The tagDetection(enable)
method enables or disables apriltag detection.
Parameters |
Description |
---|---|
enable |
|
Returns: None.
colorDetection()#
The colorDetection(enable, merge)
method enables or disables color and code object detection.
Parameters |
Description |
---|---|
enable |
|
merge |
A boolean value which enables or disables the merging of adjacent color detections. The default is |
Returns: None.
modelDetection(enable)#
The modelDetection(enable)
method enables or disables AI model object detection.
Parameters |
Description |
---|---|
enable |
|
Returns: None.
startAwb()#
The startAwb()
method runs auto white balance.
Returns: None.
set()#
The set(desc)
method sets a new Color Signature or Color Code.
Parameters |
Description |
---|---|
desc |
Returns: None.
timestamp()#
The timestamp()
method requests the timestamp of the last received status packet from the AI Vision Sensor.
Returns: Timestamp of the last status packet as an unsigned 32-bit integer in milliseconds.
installed()#
The installed()
method checks for device connection.
Returns: true
if the AI Vision Sensor is connected. false
if it is not.