Όραμα Τεχνητής Νοημοσύνης#

Εισαγωγή#

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

Ο αισθητήρας όρασης AI έχει ανάλυση 320×240 pixel. Η αρχή των αξόνων (0, 0) βρίσκεται στην επάνω αριστερή γωνία, τοποθετώντας το κέντρο του αισθητήρα στο (160, 120), όπως φαίνεται στο παρακάτω διάγραμμα:

Ένα διάγραμμα που δείχνει την ανάλυση του αισθητήρα όρασης AIM AI, με τη συντεταγμένη 0,0 επάνω αριστερά του διαγράμματος, 320,0 επάνω δεξιά και 0,240 κάτω αριστερά, με 160,120 ακριβώς στο κέντρο.

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

Ενέργειες — Εμφάνιση ή απόκρυψη της ροής κάμερας AI Vision.

Λήψη αντικειμένου — Εντοπισμός αν το ρομπότ κρατάει κάποιο αντικείμενο.

  • get_data — Returns a tuple of detected objects for a specific signature.

  • has_sports_ball — Returns whether the robot has a sports ball.

  • has_any_barrel — Returns whether the robot has any type of barrel.

  • has_blue_barrel — Returns whether the robot has a blue barrel.

  • has_orange_barrel — Returns whether the robot has an orange barrel.

Properties — Object data returned from get_data.

  • exists — Whether the object exists in the current detection as a Boolean.

  • 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.

  • bearing — Horizontal angle relative to the front of the robot.

  • rotation — Orientation of the object.

  • 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.

  • type — Returns the object’s type (AI, Tag, Color, or Code).

Κατασκευαστές — Ορίστε υπογραφές και κωδικούς χρωμάτων.

Ενέργειες#

show_aivision#

show_aivision displays the AI Vision Sensor’s live data feed on the robot’s screen. The live data feed will cover any other images or text on the screen.

Note: The screen will not display any other images or text unless hide_aivision is used to hide the feed.

Usage:
robot.screen.show_aivision()

Παράμετροι

Περιγραφή

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

# Watch the AI Vision Sensor detect AI Classifications
# and AprilTag IDs as you move the robot
robot.screen.show_aivision()

hide_aivision#

hide_aivision removes the AI Vision Sensor’s live data feed from the robot’s screen.

Usage:
robot.screen.hide_aivision()

Παράμετροι

Περιγραφή

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

# View the AI Vision Sensor's feed for five seconds
robot.screen.show_aivision()
wait(5, SECONDS)
robot.screen.hide_aivision()

tag_detection#

tag_detection enables or disables the AprilTag ID detection, where the state is a Boolean value.

Ο αισθητήρας μπορεί να ανιχνεύσει τα AprilTag IDs από 0 έως 36 από την οικογένεια Circle21h7.

Usage:
robot.vision.tag_detection(state)

Παράμετροι

Περιγραφή

state

Values are: True, which enables AprilTag ID detection, or False, which disables AprilTag ID detection.

robot.screen.set_font(PROP30)

# Cut off AprilTag ID detection after 5 seconds
while True:
    if timer.time(SECONDS) > 5:
        robot.vision.tag_detection(False)

    robot.screen.clear_screen()
    robot.screen.set_cursor(3, 1)
    apriltags = robot.vision.get_data(ALL_TAGS)

    if apriltags[0].exists:
        robot.screen.print("AprilTag ID detected!")
    else:
        robot.screen.print("Nothing detected!")

    wait(0.1, SECONDS)

Αποκτητές#

get_data#

get_data filters data from the AI Vision Sensor 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.

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

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

Usage:
robot.vision.get_data(signature, count)

Παράμετροι

Περιγραφή

signature

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

  • ALL_VISION - Sports balls, barrels, VEX AIM Coding Robots, AprilTag IDs, colors, and color codes
  • ALL_CARGO - Sports balls and barrels
  • ALL_TAGS - All AprilTag IDs
  • ALL_COLORS - All configured color signatures and color codes
  • SPORTS_BALL - Only sports balls
  • BLUE_BARREL - Only blue barrels
  • ORANGE_BARREL - Only orange barrels
  • AIM_ROBOT - All VEX AIM Coding Robots
  • TAG0 through TAG37 - A single AprilTag ID from 0 to 37
  • NAME - Color signature or color code where NAME is the name configured in the AI Vision Utility.

count

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

Σημείωση: Τα AprilTag IDs 5 έως 37 μπορούν να ληφθούν χρησιμοποιώντας τα εκτυπωμένα AprilTag IDs από το AIM Printables.

# Move forward if a sports ball is detected
while True:
    ball = robot.vision.get_data(SPORTS_BALL)
    if ball[0].exists:
        robot.move_for(10, 0)
    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(robot.vision.get_data(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(robot.vision.get_data(ALL_TAGS), key=lambda tag: tag.height)
    for tag in apriltags_by_height:
        print(tag.height)
    wait(1, SECONDS)

Προβολή δεδομένων#

Printing the tuple returned by get_data displays a list of all properties of all detected objects:

# Display properties of all detected AprilTag IDs
while True:
    vision_data = robot.vision.get_data(ALL_TAGS)

    if vision_data[0].exists:
        break

    wait(0.25, SECONDS)

print(vision_data)

Στιγμιότυπο οθόνης του παραθύρου της κονσόλας που εμφανίζει την έξοδο εντοπισμού σφαλμάτων για τα αναγνωριστικά AprilTag που εντοπίστηκαν. Το κείμενο παραθέτει το 'Αντικείμενο #0' με πεδία όπως exists: True, type: AprilTag ID, id: 2, centerX: 223, centerY: 54, originX: 210, originY: 42, width: 27, height: 23, bearing: 14.1, και rotation: 0.0, ακολουθούμενο από μια γραμμή διαχωρισμού και την αρχή του 'Αντικειμένου #1' με exists: True, type: AprilTag ID, id: 4, και centerX: 122.

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

Ο αισθητήρας όρασης AIM AI μπορεί να ανιχνεύσει αυτές τις ταξινομήσεις AI:

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

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

Υπογραφή

0

Μπάλα

SPORTS_BALL

1

Μπλε βαρέλι

BLUE_BARREL

2

Πορτοκαλί βαρέλι

ORANGE_BARREL

3

Ρομπότ AIM

AIM_ROBOT

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

A color signature is a unique color that the AI Vision Sensor can recognize. These signatures allow the sensor to detect and track objects based on their color. Once a Color Signature is configured, the sensor can identify objects with that specific color in its field of view. Color signatures are used with get_data to process and detect colored objects in real-time.

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

# Display if any objects match the Red_Box signature
while True:
    robot.screen.set_cursor(1, 1)
    robot.screen.clear_row(1)
    # Change to any configured Color Signature
    ai_objects = robot.vision.get_data(Red_Box)
    if ai_objects[0].exists:
        robot.screen.print("Color signature detected!")

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

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

Η διεπαφή του AI Vision Utility δείχνει έναν συνδεδεμένο αισθητήρα όρασης που ανιχνεύει δύο γειτονικά αντικείμενα, ένα μπλε πλαίσιο στα αριστερά και ένα κόκκινο πλαίσιο στα δεξιά, ομαδοποιημένα σε ένα ενιαίο λευκό πλαίσιο οριοθέτησης με την ένδειξη BlueRed. Οι πληροφορίες ανίχνευσης περιλαμβάνουν τη γωνία (A:11°), τις συντεταγμένες (X:143, Y:103), το πλάτος (W:233) και το ύψος (H:108). Στο δεξί πλαίσιο, παρατίθενται τρεις χρωματικές υπογραφές: Red_Box, Blue_Box και BlueRed, με ρυθμιζόμενα εύρη απόχρωσης και κορεσμού. Η υπογραφή BlueRed συνδυάζει το Blue_Box και το Red_Box. Κάτω από την τροφοδοσία βίντεο υπάρχουν κουμπιά με την ένδειξη Freeze Video (Πάγωμα βίντεο), Copy Image (Αντιγραφή εικόνας), Save Image (Αποθήκευση εικόνας) και Close (Κλείσιμο).

# Display if any objects match the BlueRed code
while True:
    robot.screen.set_cursor(1, 1)
    robot.screen.clear_row(1)
    # Change to any configured Color Code
    ai_objects = robot.vision.get_data(BlueRed)
    if ai_objects[0].exists:
        robot.screen.print("Color code detected!")

has_sports_ball#

has_sports_ball returns a Boolean indicating whether the robot currently has a sports ball.

  • True — The robot has a sports ball.

  • False — The robot does not have a sports ball.

Usage:
robot.has_sports_ball()

Παράμετροι

Περιγραφή

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

# Kick when the robot has a sports ball
while True:
    if robot.has_sports_ball():
        robot.kicker.kick(MEDIUM)

    wait(50, MSEC)

has_any_barrel#

has_any_barrel returns a Boolean indicating whether the robot currently has any type of barrel.

  • True — The robot has a barrel.

  • False — The robot does not have a barrel.

Usage:
robot.has_any_barrel()

Παράμετροι

Περιγραφή

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

# Push a barrel away when detected
while True:
    if robot.has_any_barrel():
        robot.kicker.place()

    wait(50, MSEC)

has_blue_barrel#

has_blue_barrel returns a Boolean indicating whether the robot currently has a blue barrel.

  • True — The robot has a blue barrel.

  • False — The robot does not have a blue barrel.

Usage:
robot.has_blue_barrel()

Παράμετροι

Περιγραφή

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

# Push a blue barrel away when detected
while True:
    if robot.has_blue_barrel():
        robot.kicker.place()

    wait(50, MSEC)

has_orange_barrel#

has_orange_barrel returns a Boolean indicating whether the robot currently has an orange barrel.

  • True — The robot has an orange barrel.

  • False — The robot does not have an orange barrel.

Usage:
robot.has_orange_barrel()

Παράμετροι

Περιγραφή

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

# Push an orange barrel away when detected
while True:
    if robot.has_orange_barrel():
        robot.kicker.place()

    wait(50, MSEC)

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

There are twelve properties that are included with each object stored in a tuple after the robot.vision.get_data method is used.

All property values except .id, .score, and .type describe the detected object’s position, size, orientation, or bearing at the moment robot.vision.get_data was used. These values are measured in pixels or degrees, based on the sensor’s 320 by 240 pixel resolution.

Ένα μπλε βαρέλι με μια πορτοκαλί λωρίδα βρίσκεται στο κέντρο του πλαισίου, περιτριγυρισμένο από ένα μαύρο πλαίσιο οριοθέτησης. Οι άξονες x και y επισημαίνονται με 0 έως 320 από αριστερά προς τα δεξιά στην κορυφή και με 0 έως 240 από πάνω προς τα κάτω κατά μήκος της αριστερής πλευράς αντίστοιχα.

.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:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    ai_objects = robot.vision.get_data(ALL_CARGO)

    if ai_objects[0].exists:
        if ai_objects[1].exists:
            robot.screen.print("At least 2")
        else:
            robot.screen.print("Less than 2")
    wait(0.1, SECONDS)

.width#

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

Σημείωση: Οι τιμές των pixel είναι σχετικές με το σύστημα συντεταγμένων του αισθητήρα. Δείτε το διάγραμμα στην Εισαγωγή για αναφορά.

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

# Move towards a Blue Barrel until its width is
# larger than 100 pixels
while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if barrel[0].width < 100:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.height#

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

Σημείωση: Οι τιμές των pixel είναι σχετικές με το σύστημα συντεταγμένων του αισθητήρα. Δείτε το διάγραμμα στην Εισαγωγή για αναφορά.

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

# Move towards a Blue Barrel until its height is
# larger than 100 pixels
while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if barrel[0].height < 100:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    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.

Σημείωση: Οι τιμές των pixel είναι σχετικές με το σύστημα συντεταγμένων του αισθητήρα. Δείτε το διάγραμμα στην Εισαγωγή για αναφορά.

Ένα μπλε βαρέλι με μια πορτοκαλί λωρίδα βρίσκεται στο κέντρο του πλαισίου, περιτριγυρισμένο από ένα μαύρο πλαίσιο οριοθέτησης. Μια κάθετη κόκκινη διακεκομμένη γραμμή εκτείνεται από την κορυφή του πλαισίου προς τα κάτω μέχρι το κέντρο του πλαισίου οριοθέτησης, υποδεικνύοντας τη συντεταγμένη Χ του κέντρου.

# Turn slowly until a Blue Barrel is centered in
# front of the robot
robot.set_turn_velocity(30)
robot.turn(RIGHT)

while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if 140 < barrel[0].centerX < 180:
            robot.stop_all_movement()

    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.

Σημείωση: Οι τιμές των pixel είναι σχετικές με το σύστημα συντεταγμένων του αισθητήρα. Δείτε το διάγραμμα στην Εισαγωγή για αναφορά.

Ένα μπλε βαρέλι με μια πορτοκαλί λωρίδα βρίσκεται στο κέντρο του πλαισίου, περιτριγυρισμένο από ένα μαύρο πλαίσιο οριοθέτησης. Μια οριζόντια κόκκινη διακεκομμένη γραμμή εκτείνεται από την αριστερή πλευρά του πλαισίου μέχρι το κέντρο του πλαισίου οριοθέτησης, υποδεικνύοντας τη συντεταγμένη Υ του κέντρου.

# Move towards a Blue Barrel until its
# center y-coordinate is more than 140 pixels
while True:
    barrel = robot.vision.get_data(BLUE_BARREL)

    if barrel[0].exists:
        if barrel[0].centerY < 140:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.bearing#

.bearing returns a decimal (float) representing how far an object is to the left or right of the center of the AI Vision Sensor’s view as a degree. A value of 0 means it’s centered, positive values mean the object is to the right, and negative values mean the object is to the left.

Διάγραμμα από πάνω προς τα κάτω που δείχνει ένα ρομπότ κωδικοποίησης VEX AIM κεντραρισμένο σε κυκλική βάση με μια κάθετη γραμμή αναφοράς και μια κόκκινη γραμμή υπό γωνία προς μια αθλητική μπάλα στα αριστερά, με την ένδειξη -30 μοίρες. Διάγραμμα από πάνω προς τα κάτω που δείχνει ένα ρομπότ κωδικοποίησης VEX AIM κεντραρισμένο σε κυκλική βάση με μια κάθετη γραμμή αναφοράς και μια κόκκινη γραμμή υπό γωνία προς μια αθλητική μπάλα στα δεξιά, με την ένδειξη 30 μοίρες.
# Turn to keep the Blue Barrel directly in front
robot.set_turn_velocity(40)
while True:
    vision_data = robot.vision.get_data(BLUE_BARREL)

    if vision_data[0].exists:

        if vision_data[0].bearing > 5:
            robot.turn(RIGHT)
        elif vision_data[0].bearing < -5:
            robot.turn(LEFT)
        else:
            robot.stop_all_movement()

    else:
        robot.stop_all_movement()

    wait(0.1, SECONDS)

.rotation#

.rotation returns the object’s orientation on the AI Vision Sensor’s viewing plane, measured in degrees from 0 to 359. A Color Code is 0° when its colors are arranged in a horizontal line (e.g., Red–Blue). If the colors are rotated, the angle changes (e.g., arranging Blue-Red returns 180°).

Για το παρακάτω παράδειγμα, ο Χρωματικός Κώδικας έχει διαμορφωθεί με κόκκινο στα αριστερά και μπλε στα δεξιά.

Σε αυτήν την εικόνα, η τοποθέτηση μπλε πάνω από κόκκινο ισοδυναμεί με την περιστροφή του αρχικού Χρωματικού Κώδικα κατά 270 μοίρες προς τα δεξιά.

Μια διεπαφή κάμερας εμφανίζει ένα κατακόρυφα στοιβαγμένο αντικείμενο με ένα μπλε πάνω μισό και ένα κόκκινο κάτω μισό, κεντραρισμένο στο πλαίσιο. Μια ετικέτα κάτω από το αντικείμενο γράφει Red_Blue A:270° CX:185 CY:81 W:93 H:150, υποδεικνύοντας το όνομα του αντικειμένου, τη γωνία περιστροφής, τις κεντρικές συντεταγμένες X και Y, το πλάτος και το ύψος. Οι γραμμές πλέγματος και οι αριθμητικοί άξονες υποδεικνύουν τις διαστάσεις της εικόνας, με το X να κυμαίνεται από 0 έως 320 και το Y από 0 έως 240.

# Slide left or right depending on how a Color Code (BlueRed)
# is rotated on the vertical plane
while True:
    # Original Color Code is Red to the left, Blue to the right
    code = robot.vision.get_data(BlueRed)

    if code[0].exists:
        # Check if Color Code is now Red on top of Blue
        if 50 < code[0].rotation < 100 :
            robot.move_at(90)

        # Check if Color Code is now Blue on top of Red
        elif 270 < code[0].rotation < 330 :
            robot.move_at(270)

        else:
            robot.stop_all_movement()
    else:
        robot.stop_all_movement()

    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.

Σημείωση: Οι τιμές των pixel είναι σχετικές με το σύστημα συντεταγμένων του αισθητήρα. Δείτε το διάγραμμα στην Εισαγωγή για αναφορά.

Ένα μπλε βαρέλι με μια πορτοκαλί λωρίδα βρίσκεται στο κέντρο του πλαισίου, περιτριγυρισμένο από ένα μαύρο πλαίσιο οριοθέτησης. Μια κάθετη κόκκινη διακεκομμένη γραμμή εκτείνεται από την κορυφή του πλαισίου έως την αριστερή άκρη του πλαισίου οριοθέτησης, υποδεικνύοντας τη συντεταγμένη Χ της αρχής του πλαισίου οριοθέτησης.

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

    orange_barrel = robot.vision.get_data(ORANGE_BARREL)

    if orange_barrel[0].exists:
        if orange_barrel[0].originX < 160:
            robot.screen.print("To the left!")
        else:
            robot.screen.print("To the right!")

    wait(50, 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.

Σημείωση: Οι τιμές των pixel είναι σχετικές με το σύστημα συντεταγμένων του αισθητήρα. Δείτε το διάγραμμα στην Εισαγωγή για αναφορά.

Ένα μπλε βαρέλι με μια πορτοκαλί λωρίδα βρίσκεται στο κέντρο του πλαισίου, περιτριγυρισμένο από ένα μαύρο πλαίσιο οριοθέτησης. Μια οριζόντια κόκκινη διακεκομμένη γραμμή εκτείνεται από την αριστερή πλευρά του πλαισίου έως την επάνω άκρη του πλαισίου οριοθέτησης, υποδεικνύοντας τη συντεταγμένη Υ της αρχής του πλαισίου οριοθέτησης.

# Display if an Orange Barrel is close or far
# from the robot
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)

    orange_barrel = robot.vision.get_data(ORANGE_BARREL)

    if orange_barrel[0].exists:
        if orange_barrel[0].originY < 80:
            robot.screen.print("Far")
        else:
            robot.screen.print("Close")

    wait(50, MSEC)

.id#

.id returns the ID of the detected AI Classification or AprilTag ID as an integer.

For an AprilTag ID, the .id property represents the detected AprilTag ID number in the range of 0 to 37. 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 = robot.vision.get_data(ALL_TAGS)

    if apriltags[0].exists:
        if apriltags[0].id == 1:
            robot.move_at(0)
    else:
        robot.stop_all_movement()

    wait(50, MSEC)

.score#

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

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

# Look confident if an Orange Barrel is detected
while True:
    barrel = robot.vision.get_data(ORANGE_BARREL)

    if barrel[0].exists:
        if barrel[0].score > 95:
            robot.screen.show_emoji(CONFIDENT)
        else:
            robot.screen.hide_emoji()

    wait(50, MSEC)

.type#

.type returns an integer that indicates the type of object detected. You can compare this value using either the type number or the corresponding named constant:

Τύπος αντικειμένου

Συμπεριλαμβανόμενα αντικείμενα

AiVision.AI_OBJECT

— Αθλητικές μπάλες
— Μπλε βαρέλια
— Πορτοκαλί βαρέλια

AiVision.TAG_OBJECT

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

AiVision.COLOR_OBJECT

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

AiVision.CODE_OBJECT

— Χρωματικοί κωδικοί

# Display if an AprilTag ID or AI Classification
# is detected
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    vision_data = robot.vision.get_data(ALL_VISION)
    if vision_data[0].exists:
        if vision_data[0].type == AiVision.AI_OBJECT:
            robot.screen.print("AI Object!")
        elif vision_data[0].type == AiVision.TAG_OBJECT:
            robot.screen.print("AprilTag ID!")
    wait(0.1, SECONDS)

# Display a list of all detected objects
while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)
    vision_data = robot.vision.get_data(ALL_VISION)

    if vision_data[0].exists:
        for obj in vision_data:
            if obj.type == AiVision.AI_OBJECT:
                robot.screen.print("- AI Object")
            elif obj.type == AiVision.TAG_OBJECT:
                robot.screen.print("- AprilTag ID")
            robot.screen.next_row()

    wait(0.1, SECONDS)

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

Creating a Color Signature#

A new Color Signature is created using the Colordesc constructor and then registered with the AI Vision Sensor using the color_description method. A Colordesc object defines 1 of up to 7 detectable color signatures for the sensor, but it must be explicitly set using color_description to take effect.

Colordesc Usage:
Colordesc(index, red, green, blue, hangle, hdsat)

Παράμετρος

Περιγραφή

index

Ένας ακέραιος αριθμός από το 1 έως το 7 που αντιπροσωπεύει τον δείκτη Χρωματικής Υπογραφής. Εάν δύο Χρωματικές Υπογραφές χρησιμοποιούν τον ίδιο δείκτη, ο δεύτερος θα αντικαταστήσει τον πρώτο.

red

Ένας ακέραιος αριθμός από 0 έως 255 για το κόκκινο στοιχείο του χρώματος.

green

Ένας ακέραιος αριθμός από 0 έως 255 για το πράσινο στοιχείο του χρώματος.

blue

Ένας ακέραιος αριθμός από 0 έως 255 για το μπλε στοιχείο του χρώματος.

hangle

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

hdsat

Μια κινητή τιμή από 0,10 έως 1,00 που αντιπροσωπεύει το εύρος κορεσμού.

color_description Usage:
robot.vision.color_description(object)

Παράμετρος

Περιγραφή

object

The Colordesc object to set as a detectable Color Signature.

# Detect a red object
red_box = Colordesc(1, 207, 19, 25, 10.00, 0.20)
robot.vision.color_description(red_box)

while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)

    red_boxes = robot.vision.get_data(red_box)

    if red_boxes[0].exists:
        robot.screen.print("Red detected!")
    else:
        robot.screen.print("No red detected.")

    wait(0.2, SECONDS)

Creating a Color Code#

A new Color Code is created using the Codedesc constructor and then activated using the code_description method. A Color Code groups 2 to 4 existing Colordesc objects into a single identifier that the AI Vision Sensor can detect as a sequence, but it must be explicitly set using code_description to take effect.

Codedesc Usage:
Codedesc(index, c1, c2, c3, c4, c5)

Παράμετρος

Περιγραφή

index

The index of the Color Code, from 1 to 8. Note: If you create two Codedesc objects with the same index, the second will override the first.

c1

The first Colordesc object in the code.

c2

The second Colordesc object in the code.

c3

Optional. A third Colordesc object.

c4

Optional. A fourth Colordesc object.

code_description Usage:
robot.vision.code_description(object)

Παράμετρος

Περιγραφή

object

A Codedesc object to register as a detectable Color Code.

# Create Color Signatures
red_box = Colordesc(1, 207, 19, 25, 10.00, 0.20)
purple_box = Colordesc(2, 98, 18, 227, 10.00, 0.20)

robot.vision.color_description(red_box)
robot.vision.color_description(purple_box)

# Detect a red_purple Color Code
red_purple = Codedesc(1, red_box, purple_box)
robot.vision.code_description(red_purple)

while True:
    robot.screen.clear_screen()
    robot.screen.set_cursor(1, 1)

    code_objects = robot.vision.get_data(red_purple)

    if code_objects[0].exists:
        robot.screen.print("Code detected!")
    else:
        robot.screen.print("No code detected.")

    wait(0.2, SECONDS)