Αισθητήρας όρασης AI#

Εισαγωγή#

The aivision class is used to control and access data from the EXP AI Vision Sensor. The AI Vision Sensor can detect:

  • Ταξινομήσεις Τεχνητής Νοημοσύνης (όπως αντικείμενα παιχνιδιού)

  • Αναγνωριστικά ετικέτας AprilTag

  • Προσαρμοσμένες χρωματικές υπογραφές

  • Προσαρμοσμένοι κωδικοί χρωμάτων

Παρέχει δεδομένα αντικειμένου, όπως θέση, μέγεθος, προσανατολισμό, αναγνωριστικό ταξινόμησης και βαθμολογία εμπιστοσύνης.

The sensor processes visual information using an onboard AI model selected in the AI Vision Utility within VEXcode. The selected model determines which AI Classifications the sensor can detect. When using VS Code, the AI model must first be configured in VEXcode before it can be used in your program. Detected objects are returned through the objects array after takeSnapshot is called.

Κατασκευαστές κλάσεων#

aivision(
  int32_t index,
  Args&... sigs );

Παράμετροι#

Παράμετρος

Τύπος

Περιγραφή

index

int32_t

The Smart Port that the AI Vision Sensor is connected to, written as PORTx, where x is the port number (for example, PORT1).

sigs

colordesc, codedesc, or AI constants

One or more detection types to register with the sensor:

  • aivision::ALL_AIOBJS — All AI Classifications
  • aivision::ALL_TAGS — All AprilTag IDs
  • aivision::colordesc — Custom Color Signature
  • aivision::codedesc — Custom Color Code

Μοντέλα και Ταξινομήσεις Τεχνητής Νοημοσύνης#

Ο αισθητήρας όρασης AI μπορεί να ανιχνεύσει διαφορετικά αντικείμενα με συγκεκριμένες ταξινομήσεις AI. Ανάλογα με το μοντέλο ταξινόμησης AI που επιλέγεται κατά τη διαμόρφωση του αισθητήρα όρασης AI στο παράθυρο Συσκευές, μπορούν να ανιχνευθούν διαφορετικά αντικείμενα. Τα διαθέσιμα μοντέλα είναι:

Στοιχεία τάξης

Αριθμός Ταυτότητας

Ταξινόμηση Τεχνητής Νοημοσύνης

0

blueBall

1

greenBall

2

redBall

3

blueRing

4

greenRing

5

redRing

6

blueCube

7

greenCube

8

redCube

Διαγωνισμός Ρομποτικής VEX V5 με Υψηλά Στοιχήματα

Αριθμός Ταυτότητας

Ταξινόμηση Τεχνητής Νοημοσύνης

0

mobileGoal

1

redRing

2

blueRing

Αντιμετώπιση του Διαγωνισμού Ρομποτικής VEX V5

Αριθμός Ταυτότητας

Ταξινόμηση Τεχνητής Νοημοσύνης

0

blueBlock

1

redBlock

Παράκαμψη Διαγωνισμού Ρομποτικής VEX V5

Αριθμός Ταυτότητας

Ταξινόμηση Τεχνητής Νοημοσύνης

0

redBluePin

1

blueYellowPin

2

redYellowPin

3

yellowPin

4

cup

Παραδείγματα#

// Create Color Signatures
aivision::colordesc AIVision1__greenBox(
    1,      // index
    85,     // red
    149,    // green
    46,     // blue
    23,     // hangle
    0.23 ); // hdsat

aivision::colordesc AIVision1__blueBox(
    2,      // index
    77,     // red
    135,    // green
    125,    // blue
    27,     // hangle
    0.29 ); // hdsat

// Create a Color Code from two color signatures
aivision::codedesc AIVision1__greenBlue(
    1,                    // code index
    AIVision1__greenBox,  // first color signature
    AIVision1__blueBox ); // second color signature

// Create the AI Vision Sensor instance
aivision AIVision1(
    PORT11,                  // Smart Port
    AIVision1__greenBlue,    // color code
    aivision::ALL_AIOBJS );  // enable AI Classifications

Συναρτήσεις Μελών#

The aivision class includes the following member functions:

  • takeSnapshot — Captures data for a specific Color Signature, Color Code, AI Classification group, or AprilTag ID group.

  • installed — Returns whether the AI Vision Sensor is connected to the EXP Brain.

To access detected object data after calling takeSnapshot, use the available Properties.

Before calling any aivision member functions, an aivision instance must be created, as shown below:

/* This constructor is required when using VS Code.
AI Vision Sensor configuration is generated automatically
in VEXcode using the Device Menu. Replace the values
as needed. */


// Create Color Signatures
aivision::colordesc AIVision1__greenBox(
    1,      // index
    85,     // red
    149,    // green
    46,     // blue
    23,     // hangle
    0.23 ); // hdsat

aivision::colordesc AIVision1__blueBox(
    2,      // index
    77,     // red
    135,    // green
    125,    // blue
    27,     // hangle
    0.29 ); // hdsat

// Create a Color Code from two color signatures
aivision::codedesc AIVision1__greenBlue(
    1,                    // code index
    AIVision1__greenBox,  // first color signature
    AIVision1__blueBox ); // second color signature

// Create the AI Vision Sensor instance
aivision AIVision1(
    PORT1,                   // Smart Port
    AIVision1__greenBlue,    // color code
    aivision::ALL_AIOBJS );  // enable AI Classifications

takeSnapshot#

Captures an image from the AI Vision Sensor, processes it using the selected AI model or configured color signatures, and updates the objects array.

Each call refreshes the objects array with the most recent detection results. Objects are ordered from largest to smallest (by width), beginning at index 0. If no objects are detected objectCount will be 0 and objects[i].exists will be false.

1 Λαμβάνει ένα στιγμιότυπο χρησιμοποιώντας ένα αναγνωριστικό αντικειμένου και έναν τύπο αντικειμένου.

int32_t takeSnapshot(
  uint32_t id,
  objectType type,
  uint32_t count );

2 Λαμβάνει ένα στιγμιότυπο χρησιμοποιώντας μια Υπογραφή Χρώματος.

int32_t takeSnapshot(
  const colordesc &desc,
  int32_t count = 8 );

3 Λαμβάνει ένα στιγμιότυπο χρησιμοποιώντας έναν Κωδικό Χρώματος.

int32_t takeSnapshot(
  const codedesc &desc,
  int32_t count = 8 );

4 Λαμβάνει ένα στιγμιότυπο χρησιμοποιώντας ένα AprilTag ID.

int32_t takeSnapshot(
  const tagdesc &desc,
  int32_t count = 8 );

5 Λαμβάνει ένα στιγμιότυπο χρησιμοποιώντας μια Ταξινόμηση AI.

int32_t takeSnapshot(
  const aiobjdesc &desc,
  int32_t count = 8 );

6 Λαμβάνει ένα στιγμιότυπο χρησιμοποιώντας έναν Περιγραφέα Αντικειμένου.

int32_t takeSnapshot(
  const objdesc &desc,
  int32_t count = 8 );

Parameters

Παράμετρος

Τύπος

Περιγραφή

id

uint32_t

The identifier of the object to detect when using the (id, type, count) function. The meaning depends on type:

  • colorObject — Color Descriptor index (1–7)
  • codeObject — Color Code index (1–8)
  • modelObject — AI Classification ID
  • tagObject — AprilTag ID (0–36)

Note: In VEXcode, AI Classification names (such as blueBall) may be used directly. In VS Code, the numeric ID must be used.

type

objectType

Specifies the category of object associated with id:

  • objectType::tagObject — Detects AprilTag IDs
  • objectType::colorObject — Detects Color Signatures
  • objectType::codeObject — Detects Color Codes
  • objectType::modelObject — Detects AI Classifications
  • objectType::allObject — Detects everything the sensor can recognize

desc

colordesc &, codedesc &, tagdesc &, aiobjdesc &, or objdesc &

Descriptor used to detect a specific object. Passed directly to takeSnapshot, for example:

  • AIVision1.takeSnapshot(AIVision1__greenBox);
  • AIVision1.takeSnapshot(aivision::ALL_AIOBJS);
Predefined descriptor constants:
  • aivision::ALL_TAGS — Detects all AprilTag IDs
  • aivision::ALL_COLORS — Detects all configured Color Signatures
  • aivision::ALL_CODES — Detects all configured Color Codes
  • aivision::ALL_AIOBJS — Detects all AI Classifications
  • aivision::ALL_OBJECTS — Detects everything the sensor can recognize

count

uint32_t / int32_t

Μέγιστος αριθμός αντικειμένων που αποθηκεύονται από το στιγμιότυπο. Προεπιλογή: 8.

Επιστρεφόμενες τιμές

Returns an int32_t representing the number of detected objects matching the specified signature or detection type.

Σημειώσεις

  • Ο αισθητήρας όρασης AI πρέπει να τραβήξει ένα στιγμιότυπο πριν είναι δυνατή η πρόσβαση στα δεδομένα του αντικειμένου.

  • The objects array is refreshed on every call.

  • When count is specified, only the largest detected objects (up to the specified amount) are stored.

Οι ταξινομήσεις AI εξαρτώνται από το μοντέλο που έχει επιλεγεί στο AI Vision Utility στο VEXcode.

Παραδείγματα

// Move forward if an object is detected
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);
  if (AIVision1.objects[0].exists) {
    Drivetrain.driveFor(forward, 50, mm);
  }
  wait(50, msec);
}

installed#

Επιστρέφει εάν ο αισθητήρας όρασης AI είναι συνδεδεμένος στον εγκέφαλο EXP.

Διαθέσιμες Λειτουργίες

bool installed();

Παράμετροι

Αυτή η συνάρτηση δεν δέχεται καμία παράμετρο.

Επιστρεφόμενες τιμές

Επιστρέφει μια λογική τιμή που υποδεικνύει εάν ο αισθητήρας όρασης AI είναι συνδεδεμένος:

  • true — The AI Vision Sensor is connected.

  • false — The AI Vision Sensor is not connected.

// Display a message if the AI Vision Sensor is connected
if (AIVision1.installed()){
  Brain.Screen.print("Installed!");
}

Σκηνικά θέατρου#

Calling takeSnapshot updates the AI Vision Sensor’s detection results. Each snapshot refreshes the objects array, which contains detected objects for the requested AI Classification, Color Signature, Color Code, or AprilTag ID.

AI Vision data is accessed through properties of objects stored in AIVisionSensor.objects[index], where index begins at 0.

Τα αντικείμενα ταξινομούνται από το μεγαλύτερο στο μικρότερο (ανά εμβαδόν).

Η ανάλυση εικόνας του αισθητήρα AI Vision Sensor είναι 320 × 240 pixelΟι τιμές θέσης και μεγέθους αντικειμένου αναφέρονται σε μονάδες pixel σε σχέση με την τρέχουσα προβολή του αισθητήρα.

Διατίθενται τα ακόλουθα ακίνητα:

  • objectCount — Returns the number of detected objects from the most recent snapshot.

  • largestObject — Selects the largest detected object from the most recent snapshot.

  • objects — Array containing detected objects updated by takeSnapshot.

  • .exists — Whether the object entry contains valid data.

  • .width — Width of the detected object in pixels.

  • .height — Height of the detected object in pixels.

  • .centerX — X position of the object’s center in pixels.

  • .centerY — Y position of the object’s center in pixels.

  • .originX — X position of the object’s top-left corner in pixels.

  • .originY — Y position of the object’s top-left corner in pixels.

  • .angle — Orientation of a Color Code or AprilTag ID in degrees.

  • .id — Classification ID or AprilTag ID.

  • .score — Confidence score for AI Classifications.

objectCount#

objectCount returns the number of items inside the objects array as an integer.

Syntax
AIVisionSensor.objectCount

Components

Συστατικό

Περιγραφή

AIVisionSensor

Το όνομα της παρουσίας του αισθητήρα AI Vision Sensor.

Παραδείγματα

// Display the number of detected objects
while (true) {
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.clearLine(1);
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);
  if (AIVision1.objects[0].exists) {
    Brain.Screen.print("%d", AIVision1.objectCount);
  }
  wait(50, msec);
}

largestObject#

largestObject retrieves the largest detected object from the objects array.

This method can be used to always get the largest object from objects without specifying an index.

Syntax
AIVisionSensor.largestObject

Components

Συστατικό

Περιγραφή

AIVisionSensor

Το όνομα της παρουσίας του αισθητήρα AI Vision Sensor.

Παραδείγματα

// Display the closest AprilTag ID
while (true) {
  Brain.Screen.setCursor(1, 1);
  Brain.Screen.clearLine(1);
  AIVision1.takeSnapshot(aivision::ALL_TAGS);
  if (AIVision1.objects[0].exists) {
    Brain.Screen.print("%d", AIVision1.largestObject.id);
  }
  wait(50, msec);
}

objects#

objects returns an array of detected object properties. Use the array to access specific property values of individual objects.

There are ten properties that are included with each object stored in the objects array after takeSnapshot is used.

All property values except id and score describe the detected object’s position and size in the AI Vision Sensor’s view at the moment takeSnapshot was used. These values are measured in pixels, based on the sensor’s 320 by 240 pixel resolution.

Syntax
AIVisionSensor.objects[index].property

Components

Συστατικό

Περιγραφή

AIVisionSensor

Το όνομα της παρουσίας του αισθητήρα AI Vision Sensor.

index

The object index in the array. Index begins at 0.

property

Μία από τις διαθέσιμες ιδιότητες αντικειμένου.

.υπάρχει#

.exists returns whether the specified object index contains a valid detected object.

Πρόσβαση

SensorName.objects[index].exists

Επιστρεφόμενες τιμές

Επιστρέφει μια λογική τιμή που υποδεικνύει εάν ο καθορισμένος δείκτης αντικειμένου περιέχει ένα έγκυρο ανιχνευμένο αντικείμενο:

  • true — A valid object exists at the specified index.
  • false — No object exists at the specified index.

Παραδείγματα

// Move forward if an object is detected
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);
  if (AIVision1.objects[0].exists) {
    Drivetrain.driveFor(forward, 50, mm);
  }
  wait(50, msec);
}

.πλάτος#

.width returns the width of the detected object.

Πρόσβαση

SensorName.objects[index].width

Επιστρεφόμενες τιμές

Returns an int16_t representing the width of the detected object in pixels. The value ranges from 1 to 320.

Παραδείγματα

// Approach an object until it's at least 100 pixels wide
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);

  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].width < 100) {
      Drivetrain.drive(forward);
    } else {
      Drivetrain.stop();
    }
  } else {
    Drivetrain.stop();
  }
  wait(50, msec);
}

.ύψος#

.height returns the height of the detected object.

Πρόσβαση

SensorName.objects[index].height

Επιστρεφόμενες τιμές

Returns an int16_t representing the height of the detected object in pixels. The value ranges from 1 to 240.

Παραδείγματα

// Approach an object until it's at least 90 pixels tall
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);

  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].height < 90) {
      Drivetrain.drive(forward);
    } else {
      Drivetrain.stop();
    }
  } else {
    Drivetrain.stop();
  }
  wait(50, msec);
}

.centerX#

.centerX returns the x-coordinate of the center of the detected object.

Πρόσβαση

SensorName.objects[index].centerX

Επιστρεφόμενες τιμές

Returns an int16_t representing the x-coordinate of the object’s center in pixels. The value ranges from 0 to 320.

Παραδείγματα

// Turn until an object is directly in front of the sensor
Drivetrain.setTurnVelocity(10, percent);
Drivetrain.turn(right);
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);

  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].centerX > 140 && AIVision1.objects[0].centerX < 180) {
      Drivetrain.stop();
    }
  }
  wait(10, msec);
}

.centerY#

.centerY returns the y-coordinate of the center of the detected object.

Πρόσβαση

SensorName.objects[index].centerY

Επιστρεφόμενες τιμές

Returns an int16_t representing the y-coordinate of the object’s center in pixels. The value ranges from 0 to 240.

Παραδείγματα

// Approach an object until it's close to the sensor
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);

  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].centerY < 150) {
      Drivetrain.drive(forward);
    } else {
      Drivetrain.stop();
    }
  } else {
    Drivetrain.stop();
  }
  wait(50, msec);
}

.γωνία#

.angle returns the orientation of the detected Color Code or AprilTag ID.

Πρόσβαση

SensorName.objects[index].angle

Επιστρεφόμενες τιμές

Returns a float representing the rotation of the detected Color Code or AprilTag ID in degrees. The value ranges from 0 to 359.9.

Παραδείγματα

// Turn left or right depending on how a configured
// Color Code is rotated
while (true) {
  AIVision1.takeSnapshot(AIVision1__redBlue);
  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].angle > 50 && AIVision1.objects[0].angle < 100) {
      Drivetrain.turn(right);
    }
    else if (AIVision1.objects[0].angle > 270 && AIVision1.objects[0].angle < 330) {
      Drivetrain.turn(left);
    }
    else {
      Drivetrain.stop();
    }
  } else {
    Drivetrain.stop();
  }
  wait(50, msec);
}

.originX#

.originX returns the x-coordinate of the top-left corner of the detected object’s bounding box.

Πρόσβαση

SensorName.objects[index].originX

Επιστρεφόμενες τιμές

Returns an int16_t representing the x-coordinate of the object’s bounding box origin in pixels. The value ranges from 0 to 320.

Παραδείγματα

// Display if an object is to the left or the right
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);
  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].originX < 120) {
      Brain.Screen.print("To the left!");
    } else {
      Brain.Screen.print("To the right!");
    }
  } else {
    Brain.Screen.print("No objects");
  }
  wait(100, msec);
}

.originY#

.originY returns the y-coordinate of the top-left corner of the detected object’s bounding box.

Πρόσβαση

SensorName.objects[index].originY

Επιστρεφόμενες τιμές

Returns an int16_t representing the y-coordinate of the object’s bounding box origin in pixels. The value ranges from 0 to 240.

Παραδείγματα

// Display if an object is close or far
while (true) {
  Brain.Screen.clearScreen();
  Brain.Screen.setCursor(1, 1);
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);
  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].originY < 110) {
      Brain.Screen.print("Close");
    } else {
      Brain.Screen.print("Far");
    }
  }
  wait(100, msec);
}

.ταυτότητα#

.id returns the detected AprilTag ID or AI Classification ID.

Πρόσβαση

SensorName.objects[index].id

Επιστρεφόμενες τιμές

Returns an int32_t representing the ID of the detected object:

Παραδείγματα

// Move forward when AprilTag ID 1 is detected
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_TAGS);
  if (AIVision1.objects[0].exists) {
    if (AIVision1.objects[0].id == 1) {
      Drivetrain.drive(forward);
    }
  } else {
    Drivetrain.stop();
  }
  wait(50, msec);
}

.σκορ#

.score returns the confidence score of the detected AI Classification.

Πρόσβαση

SensorName.objects[index].score

Επιστρεφόμενες τιμές

Returns an int16_t indicating the confidence score of the detected AI Classification between 1 and 100.

Μια χαμηλότερη βαθμολογία σημαίνει ότι ο αισθητήρας είναι λιγότερο σίγουρος για το ανιχνευμένο αντικείμενο, ενώ μια υψηλότερη βαθμολογία σημαίνει ότι ο αισθητήρας είναι πιο σίγουρος.

Παραδείγματα

// Display if a score is confident
while (true) {
  AIVision1.takeSnapshot(aivision::ALL_AIOBJS);

  if (AIVision1.objects[0].exists) {
    Brain.screen.clearScreen();
    Brain.screen.setCursor(1, 1);

    if (AIVision1.objects[0].score > 95) {
      Brain.Screen.print("Confident");
    } else {
      Brain.Screen.print("Not confident");
    }
  }
  wait(50, msec);
}