人工智能视觉#
介绍#
The VEX AIM Coding Robot’s AI Vision Sensor detects and tracks objects, colors, and AprilTag IDs. This allows the robot to analyze its surroundings, follow objects, and react based on detected visual data.
Below is a list of all blocks:
Actions — Control the AI Vision feed and capture object data.
AI Vision viewer — Enables or disables the live AI Vision feed on the robot’s screen.
get object data — Captures data for a specific object type, such as colors, pre-trained objects, or AprilTag IDs.
Settings — Adjust which detected objects are accessed.
set AI Vision object item — Selects a specific object from the detected object list.
Values — Return object presence, classification, and properties.
has object? — Checks if the robot is holding a detected object.
AI Vision object exists? — Returns whether an object is detected.
AI Vision object is? — Checks if a detected object matches a specific classification.
AI Vision object is AprilTag ID? — Checks if a detected AprilTag ID matches a specific ID.
AI Vision object count — Returns the number of detected objects.
AI Vision object property — Returns details such as:
行动#
AI 视觉查看器#
AI Vision 查看器 模块用于在机器人屏幕上启用或禁用实时 AI Vision 图像。启用后,屏幕将显示实时传感器数据,并阻止显示其他图像或文本。如需显示其他内容,请使用此模块隐藏图像。
[显示 v]AI 视觉仪在屏幕上的查看器
参数 |
描述 |
|---|---|
地位 |
Controls the display of the data feed on the robot’s screen:
|
例子
当开始
[View the AI Vision Sensor's feed for five seconds.]
[显示 v]AI 视觉仪在屏幕上的查看器
等待 [5] 秒
[隐藏 v]AI 视觉仪在屏幕上的查看器
获取对象数据#
The get object data block filters data from the AI Vision Sensor frame. The AI Vision Sensor can detect signatures that include pre-trained objects, AprilTag IDs, or configured colors and color codes.
必须先在 AI Vision Utility 中配置颜色和颜色代码,然后才能将其与此块一起使用。
该数据集存储的对象按宽度从大到小排序,从索引 0 开始。可以使用 AI Vision 对象属性 块访问每个对象的属性。如果未检测到匹配的对象,则返回空数据集。
从 AI 视觉仪获取 [运动球 v] 数据
范围 |
描述 |
|---|---|
签名 |
Filters the dataset to only include data of the given signature. Available signatures are:
|
例子
当开始
[Move forward if a sports ball is detected.]
永久循环
从 AI 视觉仪获取 [运动球 v] 数据
如果 <AI 视觉仪对象存在?> 那么
将 [向前 v] 移至 [10] [毫米 v] ▶
色彩签名#
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 in the AI Vision Utility, the sensor can identify objects with that specific color in its field of view.
Color Signatures are used in the get object data block to process and detect colored objects in real-time.

例子
当开始
[Display if any objects matching the Red_Box signature is detected.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[Change the signature to any configured Color Signature.]
从 AI 视觉仪获取 [Red_Box v] 数据
如果 <AI 视觉仪对象存在?> 那么
在屏幕上打印 [Color signature detected!]▶
颜色代码#
A Color Code is a structured pattern made up of 2 to 4 Color Signatures arranged in a specific order. Once a Color Code is configured in the AI Vision Utility, the sensor can recognize predefined patterns of colors.
颜色代码对于识别复杂物体、与游戏元素对齐或为自主导航创建唯一标记特别有用。

例子
当开始
[Display if any objects matching the BlueRed code is detected.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[Change the signature to any configured Color Code.]
从 AI 视觉仪获取 [BlueRed v] 数据
如果 <AI 视觉仪对象存在?> 那么
在屏幕上打印 [Color code detected!]▶
设置#
设置 AI Vision 对象项#
设置 AI Vision 对象项 块设置要使用数据集中的哪个项。
设定 AI 视觉仪对象标号为 (1)
参数 |
描述 |
|---|---|
物品 |
数据集中要使用的项目数量。 |
例子
当开始
[Display the width of the smallest detected object.]
永久循环
从 AI 视觉仪获取 [所有货物 v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <AI 视觉仪对象存在?> 那么
设定 AI 视觉仪对象标号为 (AI 视觉仪对象数目)
在屏幕上打印 (AI 视觉仪对象 [宽 v])▶
价值观#
有对象吗?#
The has object block returns a Boolean indicating whether the robot currently has a detected object against its Kicker.
True — The robot has the object.
False — The robot does not have the object.
<有 [运动球 v] 吗?>
范围 |
描述 |
|---|---|
目的 |
检测机器人踢球者所面对的物体:
|
例子
当开始
[Kick when the robot has a sports ball.]
永久循环
如果 <有 [运动球 v] 吗?> 那么
[中 v] 踢出对象
AI Vision 对象存在吗?#
The AI Vision object exists? block returns a Boolean indicating whether an object is detected in the dataset.
True — The dataset includes a detected object.
False — No objects were detected.
<AI 视觉仪对象存在?>
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Move forward if a sports ball is detected.]
永久循环
从 AI 视觉仪获取 [运动球 v] 数据
如果 <AI 视觉仪对象存在?> 那么
将 [向前 v] 移至 [10] [毫米 v] ▶
AI视觉的对象是什么?#
AI Vision 对象是? 块返回一个布尔值,指示检测到的对象是否与特定分类匹配。
True — The item in the dataset is the specific object.
False — The item in the dataset is not the specific object.
<AI 视觉仪对象为 [运动球 v]?>
范围 |
描述 |
|---|---|
目的 |
将物品与哪个物体进行比较:
|
例子
当开始
[Display if a sports ball is detected.]
永久循环
从 AI 视觉仪获取 [所有货物 v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <AI 视觉仪对象存在?> 那么
如果 <AI 视觉仪对象为 [运动球 v]?> 那么
在屏幕上打印 [Sports ball detected!]▶
等待 [0.5] 秒
AI Vision 对象是 AprilTag ID?#
The AI Vision object is AprilTag ID? block returns a Boolean indicating whether a detected AprilTag ID matches a specific ID.
True — The AprilTag ID is the number.
False — The AprilTag ID is not the number.
<AI 视觉仪检测到 AprilTag [1] ?>
参数 |
描述 |
|---|---|
AprilTag ID |
与检测到的 AprilTag 的 ID 号进行比较的数字。 |
AI 视觉对象计数#
AI Vision 对象计数 块以整数形式返回数据集中检测到的对象的数量。
AI 视觉仪对象数目
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Display the amount of sports balls and barrels.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 AI 视觉仪获取 [所有货物 v] 数据
如果 <AI 视觉仪对象存在?> 那么
在屏幕上打印 (AI 视觉仪对象数目)▶
结束
等待 [0.5] 秒
AI Vision 对象属性#
使用 获取对象数据块 后存储的每个对象(如下所示)都包含九个属性。
AI 视觉仪对象 [宽 v]
某些属性值基于使用获取对象数据块时检测到的物体在 AI 视觉传感器视图中的位置。AI 视觉传感器的分辨率为 320 x 240 像素。

范围 |
描述 |
|---|---|
财产 |
使用被检测对象的哪个属性: |
宽度#
width returns the width of the detected object in pixels as an integer from 1 to 320.
AI 视觉仪对象 [宽 v]

例子
当开始
[Move towards a blue barrel until its width is larger than 100 pixels.]
永久循环
从 AI 视觉仪获取 [蓝色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [宽 v]) [math_less_than v] [100]> 那么
移动 [向前 v]
结束
否则
停止移动
高度#
height returns the height of the detected object in pixels as an integer from 1 to 240.
AI 视觉仪对象 [高 v]

例子
当开始
[Move towards a blue barrel until its height is larger than 100 pixels.]
永久循环
从 AI 视觉仪获取 [蓝色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [高 v]) [math_less_than v] [100]> 那么
移动 [向前 v]
结束
否则
停止移动
中心X#
centerX returns the x-coordinate of the center of the detected object in pixels as an integer from 0 to 320.
AI 视觉仪对象 [中心X坐标 v]

例子
当开始
[Turn slowly until a blue barrel is centered in front of the robot.]
设定转向速度为 [30]%
[右 v] 转
永久循环
从 AI 视觉仪获取 [蓝色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <[140] [math_less_than v] (AI 视觉仪对象 [中心X坐标 v]) [math_less_than v] [180]> 那么
停止移动
中心Y#
centerY returns the y-coordinate of the center of the detected object in pixels as an integer from 0 to 240.
AI 视觉仪对象 [中心Y坐标 v]

例子
当开始
[Move towards a blue barrel until its center y-coordinate is more than 140 pixels.]
永久循环
从 AI 视觉仪获取 [蓝色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [中心Y坐标 v]) [math_less_than v] [140]> 那么
移动 [向前 v]
结束
否则
停止移动
原点X#
originX returns the x-coordinate of the top-left corner of the detected object’s bounding box in pixels as an integer from 0 to 320.
AI 视觉仪对象 [原点X v]

例子
当开始
[Display if an orange barrel is to the left or the right.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 AI 视觉仪获取 [橙色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [原点X v]) [math_less_than v] [160]> 那么
在屏幕上打印 [To the left!]▶
否则
在屏幕上打印 [To the right!]▶
结束
等待 [0.5] 秒
原点#
originY returns the y-coordinate of the top-left corner of the detected object’s bounding box in pixels as an integer from 0 to 240.
AI 视觉仪对象 [原点Y v]

例子
当开始
[Display if an orange barrel is close or far from the robot.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 AI 视觉仪获取 [橙色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [原点Y v]) [math_less_than v] [80]> 那么
在屏幕上打印 [Far!]▶
否则
在屏幕上打印 [Close!]▶
结束
等待 [0.5] 秒
旋转#
rotation returns the orientation of the detected AprilTag ID or Color Code as an integer in degrees from 0 to 359.
AI 视觉仪对象 [旋转 v]

例子
当开始
[Slide left or right depending on how the Color Code is rotated.]
永久循环
从 AI 视觉仪获取 [Red_Blue v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <[50] [math_less_than v] (AI 视觉仪对象 [旋转 v]) [math_less_than v] [100]> 那么
移动 [右 v]
否则如果 <[270] [math_less_than v] (AI 视觉仪对象 [旋转 v]) [math_less_than v] [330]> 那么
移动 [左 v]
否则
停止移动
结束
否则
停止移动
轴承#
bearing returns 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.
当开始
[Keep the blue barrel directly in front of the robot.]
设定转向速度为 [40]%
永久循环
从 AI 视觉仪获取 [蓝色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [方位 v]) [math_greater_than v] [5]> 那么
[右 v] 转
否则如果 <(AI 视觉仪对象 [方位 v]) [math_less_than v] [-5]> 那么
[左 v] 转
否则
停止移动
标签ID#
tagID returns the identification number of the detected AprilTag ID as an integer.
AI 视觉仪对象 [tagID v]
例子
当开始
[Move forward when AprilTag ID 0 is detected.]
永久循环
从 AI 视觉仪获取 [AprilTag ID 0 v] 数据
如果 <AI 视觉仪对象存在?> 那么
移动 [向前 v]
结束
停止移动