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

Εισαγωγή#

Ο αισθητήρας όρασης IQ AI μπορεί να ανιχνεύσει και να παρακολουθήσει αντικείμενα, χρώματα και αναγνωριστικά AprilTag. Αυτό επιτρέπει στο ρομπότ να αναλύει το περιβάλλον του, να ακολουθεί αντικείμενα και να αντιδρά με βάση τα ανιχνευμένα οπτικά δεδομένα.

For the examples below, the configured IQ AI Vision Sensor will be named ai_vision_1, and the configured Color Signature objects, such as RED_BOX, will be used in all subsequent examples throughout this API documentation when referring to AiVision class methods.

Παρακάτω είναι μια λίστα με όλες τις μεθόδους:

Λήψη δεδομένων — Λήψη δεδομένων από τον αισθητήρα όρασης IQ AI.

  • take_snapshot — Captures data for a specific signature.

  • installed — Whether the IQ AI Vision Sensor is connected to the IQ (2nd gen) Brain.

Properties — Object data returned from take_snapshot.

  • .exists — Whether the object exists in the current detection.

  • .width — Width of the detected object.

  • .height — Height of the detected object.

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

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

  • .angle — Orientation of the Color Code or AprilTag ID.

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

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

  • .id — Classification or tag ID of the object.

  • .score — Confidence score for AI Classifications.

Κατασκευαστές — Μη αυτόματη αρχικοποίηση και ρύθμιση παραμέτρων των αισθητήρων.

Αποκτητές#

take_snapshot#

take_snapshot filters data from the IQ AI Vision Sensor’s frame to a single signature — a saved description of something the sensor can recognize, such as a pre-trained object, an AprilTag ID, or a configured Color Signature or Color Code — and returns a tuple.

Οι Υπογραφές Χρώματος και Κωδικοί Χρώματος πρέπει πρώτα να ρυθμιστούν στο Vision Utility πριν μπορέσουν να χρησιμοποιηθούν με αυτήν τη μέθοδο.

Η πλειάδα αποθηκεύει αντικείμενα ταξινομημένα από το μεγαλύτερο στο μικρότερο κατά πλάτος, ξεκινώντας από τον δείκτη 0. Η πρόσβαση στις ιδιότητες κάθε αντικειμένου είναι δυνατή χρησιμοποιώντας τον δείκτη του. Επιστρέφεται μια κενή πλειάδα εάν δεν εντοπιστούν αντικείμενα που να ταιριάζουν.

Usage:
ai_vision_1.take_snapshot(SIGNATURE)

Παράμετροι

Περιγραφή

SIGNATURE

Filters the dataset to only include data of the given signature. Available signatures are:

  • Color Signatures or Color Codes - The name of the IQ AI Vision Sensor, two underscores, and then the Color Signature’s or Color Code’s name. For example: ai_vision_1__RED_BOX.
  • AiVision.ALL_AIOBJS - All detected AI Classifications depending on the model configured in the AI Vision Utility.
  • AiVision.ALL_TAGS - All AprilTag IDs.

count

Προαιρετικό. Ορίζει τον μέγιστο αριθμό αντικειμένων που μπορούν να επιστραφούν από 1 έως 24 (προεπιλογή: 8).

# Move forward if an object is detected
while True:
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
    if objects[0].exists:
        drivetrain.drive_for(FORWARD, 50, MM)
    wait(50, MSEC)

Note: The returned tuple can be sorted by any property, not just width, using Python’s sorted function. For example, sorting by AprilTag ID:

# Print each detected AprilTag ID in ascending order by ID
while True:
    apriltags = sorted(ai_vision_1.take_snapshot(AiVision.ALL_TAGS), key=id)
    for tag in apriltags:
        print(tag.id)
    wait(1, SECONDS)

Ή ταξινόμηση κατά ύψος:

# Print each detected AprilTag ID in ascending order by height
while True:
    apriltags_by_height = sorted(ai_vision_1.take_snapshot(AiVision.ALL_TAGS), key=lambda tag: tag.height)
    for tag in apriltags_by_height:
        print(tag.height)
    wait(1, SECONDS)

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

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

Αντικείμενα τάξης

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

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

0

ClassroomElements.BLUE_BALL

1

ClassroomElements.GREEN_BALL

2

ClassroomElements.RED_BALL

3

ClassroomElements.BLUE_RING

4

ClassroomElements.GREEN_RING

5

ClassroomElements.RED_RING

6

ClassroomElements.BLUE_CUBE

7

ClassroomElements.GREEN_CUBE

8

ClassroomElements.RED_CUBE

Διαγωνισμός Ρομποτικής VEX IQ Mix & Match

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

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

0

GameElementsMixAndMatch.BEAM

1

GameElementsMixAndMatch.BLUE_PIN

2

GameElementsMixAndMatch.RED_PIN

3

GameElementsMixAndMatch.ORANGE_PIN

Διαγωνισμός Ρομποτικής VEX IQ - Ανώτερο Επίπεδο

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

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

0

GameElementsLevelUp.BLUE_BEANBAG

1

GameElementsLevelUp.RED_BEANBAG

2

GameElementsLevelUp.YELLOW_BEANBAG

Χρωματικές υπογραφές#

Μια Χρωματική Υπογραφή είναι ένα μοναδικό χρώμα που μπορεί να αναγνωρίσει ο Αισθητήρας Όρασης IQ AI. Αυτές οι υπογραφές επιτρέπουν στον Αισθητήρα Όρασης IQ AI να ανιχνεύει και να παρακολουθεί αντικείμενα με βάση το χρώμα τους. Μόλις διαμορφωθεί μια Χρωματική Υπογραφή, ο αισθητήρας μπορεί να αναγνωρίσει αντικείμενα με αυτό το συγκεκριμένο χρώμα στο οπτικό του πεδίο. Οι χρωματικές υπογραφές χρησιμοποιούνται με take_snapshot για την επεξεργασία και την ανίχνευση χρωματιστών αντικειμένων σε πραγματικό χρόνο.

In order to use a configured Color Signature in a project, its name must be the name of the sensor, two underscores, and then the Color Signature’s name. For example: ai_vision_1__RED_BOX.

# Display if any objects match the RED_BOX signature
while True:
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_row(1)
    # Change to any configured Color Signature
    red_box = ai_vision_1.take_snapshot(ai_vision_1__RED_BOX)
    if red_box[0].exists:
        brain.screen.print("Color detected!")
        wait(100, MSEC)

Κωδικοί Χρώματος#

Ένας Χρωματικός Κώδικας είναι ένα δομημένο μοτίβο που αποτελείται από χρωματικές υπογραφές που είναι διατεταγμένες σε μια συγκεκριμένη σειρά. Αυτοί οι κωδικοί επιτρέπουν στον αισθητήρα όρασης IQ AI να αναγνωρίζει προκαθορισμένα μοτίβα χρωμάτων. Οι Χρωματικοί Κώδικες είναι χρήσιμοι για την αναγνώριση σύνθετων αντικειμένων ή τη δημιουργία μοναδικών δεικτών για αυτόνομη πλοήγηση.

In order to use a configured Color Code in a project, its name must be the name of the sensor, two underscores, and then the Color Code’s name. For example: ai_vision_1__BOX_CODE.

# Display if any objects match the BOX_CODE code
while True:
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_row(1)
    # Change to any configured Color Code
    box_code = ai_vision_1.take_snapshot(ai_vision_1__BOX_CODE)
    if box_code[0].exists:
        brain.screen.print("Code detected!")
        wait(100, MSEC)

installed#

installed returns a Boolean indicating whether the IQ AI Vision Sensor is currently connected to the IQ (2nd gen) Brain.

  • True — The IQ AI Vision Sensor is connected to the IQ (2nd gen) Brain.

  • False — The IQ AI Vision Sensor is not connected to the IQ (2nd gen) Brain.

Usage:
ai_vision_1.installed()

Παράμετροι

Περιγραφή

Αυτή η μέθοδος δεν έχει παραμέτρους.

# Display a message if the AI Vision Sensor is connected
if ai_vision_1.installed():
    brain.screen.print("Installed!")

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

Υπάρχουν δέκα ιδιότητες που περιλαμβάνονται σε κάθε αντικείμενο που αποθηκεύεται σε μια tuple μετά τη χρήση της take_snapshot.

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

.exists#

.exists returns a Boolean indicating if the index exists in the tuple or not.

  • True — The index exists.

  • False — The index does not exist.

# Check if at least two objects are detected
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)

    if objects[0].exists:
        if objects[1].exists:
            brain.screen.print("At least 2")

        else:
            brain.screen.print("Less than 2")
    wait(50, MSEC)

.width#

.width returns the width of the detected object in pixels, which is an integer between 1 and 320.

# Approach an object until it's at least 100 pixels wide
while True:
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)

    if objects[0].exists:
        if objects[0].width < 100:
            drivetrain.drive(FORWARD)
    else:
        drivetrain.stop()
    wait(50, MSEC)

.height#

.height returns the height of the detected object in pixels, which is an integer between 1 and 240.

# Approach an object until it's at least 90 pixels tall
while True:
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)

    if objects[0].exists:
        if objects[0].height < 90:
            drivetrain.drive(FORWARD)
    else:
        drivetrain.stop()
    wait(50, MSEC)

.centerX#

.centerX returns the x-coordinate of the detected object’s center in pixels, which is an integer between 0 and 320.

# Turn until an object is directly in front of the sensor
drivetrain.set_turn_velocity(10, PERCENT)
drivetrain.turn(RIGHT)

while True:
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)

    if objects[0].exists:
        if 140 < objects[0].centerX < 180:
            drivetrain.stop()
    wait(10,MSEC)

.centerY#

.centerY returns the y-coordinate of the detected object’s center in pixels, which is an integer between 0 and 240.

# Approach an object until the object's center is
# high enough in the field of view
while True:
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)

    if objects[0].exists:
        if objects[0].centerY < 150:
            drivetrain.drive(FORWARD)
    else:
        drivetrain.stop()
    wait(50, MSEC)

.angle#

.angle returns the orientation of the detected Color Code or AprilTag ID in degrees, which is an integer between 0 and 359.

# Turn left or right depending on how a
# configured Color Code is rotated
while True:
    box_code = ai_vision_1.take_snapshot(ai_vision_1__BOX_CODE)

    if box_code[0].exists:
        if 50 < box_code[0].angle < 100:
            drivetrain.turn(RIGHT)

        elif 270 < box_code[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 in pixels, which is an integer between 0 and 320.

# Display if an object is to the left or the right
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1,1)

    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)

    if objects[0].exists:
        if 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 in pixels, which is an integer between 0 and 240.

# Display if an object is close or far
while True:
    brain.screen.clear_screen()
    brain.screen.set_cursor(1,1)

    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)

    if objects[0].exists:
        if objects[0].originY < 110:
            brain.screen.print("Close")
        else:
            brain.screen.print("Far")

.id#

.id returns the ID of the detected AI Classification or AprilTag ID as an integer. AI Classifications depend on the model that is configured in the AI Vision Utility.

For an AprilTag ID, the .id property represents the detected AprilTag ID number in the range of 0 to 36. For an AI Classification, the .id property corresponds to the predefined ID in the AI Classifications section.

# Move forward when AprilTag ID 1 is detected
while True:
    apriltags = ai_vision_1.take_snapshot(AiVision.ALL_TAGS)

    if apriltags[0].exists:
        if apriltags[0].id == 1:
            robot.drive(FORWARD)
    else:
        drivetrain.stop()

    wait(50, MSEC)

.score#

.score returns the confidence score of the detected AI Classification as an integer between 1 and 100.

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

# Display if a score is confident
while True:
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
    brain.screen.clear_screen()
    brain.screen.set_cursor(1, 1)
    if objects[0].exists:
        if objects[0].score > 95:
            brain.screen.print("Confident")
    else:
        brain.screen.print("Not confident")

    wait(50, MSEC)

Κατασκευαστές#

Constructors are used to manually create AiVision, Colordesc, and Codedesc objects, which are necessary for configuring the IQ AI Vision Sensor outside of VEXcode.

AI Vision Sensor#

AiVision creates an IQ AI Vision Sensor.

Χρήση

Vision(port, sigs)

Παράμετροι

Περιγραφή

port

Σε ποια έξυπνη θύρα είναι συνδεδεμένος ο αισθητήρας όρασης IQ AI, από το 1 έως το 12.

sigs

Optional. The name of one or more signatures:

Παράδειγμα

ai_vision_1 = AiVision(Ports.PORT1, AiVision.ALL_AIOBJS)

# Move forward if an object is detected
while True:
    objects = ai_vision_1.take_snapshot(AiVision.ALL_AIOBJS)
    if objects[0].exists:
        drivetrain.drive_for(FORWARD, 50, MM)
    wait(50, MSEC)

Color Signature#

Colordesc creates a Color Signature. Up to seven different Color Signatures can be stored on an IQ AI Vision Sensor at once.

Χρήση:

Colordesc(index, uMin, uMax, uMean, vMin, vMax, vMean, rgb, type)

Παράμετρος

Περιγραφή

index

The Colordesc object’s index, from 1 - 7. Note: Creating two Colordesc objects with the same index number will cause the second created object to override the first.

uMin

The value from uMin in the Vision Utility.

uMax

The value from uMax in the Vision Utility.

uMean

The value from uMean in the Vision Utility.

vMin

The value from vMin in the Vision Utility.

vMax

The value from vMax in the Vision Utility.

vMean

The value from vMean in the Vision Utility.

rgb

The value from rgb in the Vision Utility.

type

The value from type in the Vision Utility.

Για να λάβετε τις τιμές για να δημιουργήσετε μια Υπογραφή Χρώματος, μεταβείτε στο Vision Utility. Μόλις ρυθμιστεί μια Υπογραφή Χρώματος, αντιγράψτε τις τιμές των παραμέτρων από το παράθυρο Διαμόρφωσης.

Παράδειγμα

# Create a new Signature RED_BOX with the Colordesc class
RED_BOX = Colordesc(1, 10121, 10757, 10439,-1657, -1223, -1440,2.5, 1)
# Create a new AI Vision Sensor "ai_vision_1" with the AiVision
# class, with the RED_BOX Signature.
ai_vision_1 = AiVision(Ports.PORT1, 100, RED_BOX)

# Move forward if a red object is detected
while True:
    red_object = ai_vision_1.take_snapshot(RED_BOX)
    if red_object[0].exists:
        drivetrain.drive_for(FORWARD, 10, MM)
    wait(5, MSEC)

Color Code#

Codedesc creates a Color Code. It requires at least two already defined Color Signatures in order to be used. Up to eight different Color Codes can be stored on a Vision Sensor at once.

Χρήση:

Codedesc(sig1, sig2, sig3, sig4, sig5)

Παράμετρος

Περιγραφή

sig1

Μια [Υπογραφή Χρώματος] που δημιουργήθηκε προηγουμένως (#color-signature).

sig2

Μια [Υπογραφή Χρώματος] που δημιουργήθηκε προηγουμένως (#color-signature).

sig3

Προαιρετικό. Μια [Υπογραφή Χρώματος] που δημιουργήθηκε προηγουμένως (#color-signature).

sig4

Προαιρετικό. Μια [Υπογραφή Χρώματος] που δημιουργήθηκε προηγουμένως (#color-signature).

sig5

Προαιρετικό. Μια [Υπογραφή Χρώματος] που δημιουργήθηκε προηγουμένως (#color-signature).

Παράδειγμα

# Create two new Signatures for a red and blue box
RED_BOX = Colordesc(1, 10121, 10757, 10439,-1657, -1223, -1440, 2.5, 1)
BLUE_BOX = Colordesc(2, -4443, -3373, -3908,6253, 7741, 6997, 2.5, 1)
# Create a Color Code for a red box to the left of a blue box
RED_BLUE = Codedesc(RED_BOX, BLUE_BOX)
# Create a new AI Vision Sensor "ai_vision_1" with the AiVision
# class, with the RED_BOX and BLUE_BOX Signatures.
ai_vision_1 = AiVision(Ports.PORT1, RED_BOX, BLUE_BOX)

# Display a message if Color Code is detected
while True:
    brain.screen.set_cursor(1, 1)
    brain.screen.clear_row(1)
    # Change to any configured Color Code
    box_code = ai_vision_1.take_snapshot(RED_BLUE)
    if box_code[0].exists:
        brain.screen.print("Code detected!")
        wait(100, MSEC)