AI 视觉#
介绍#
VEX AIM 编程机器人的 AI 视觉仪 能够检测并追踪物体、颜色以及 AprilTag ID。这使得机器人能够分析周围环境、跟随物体,并根据检测到的视觉数据做出反应。
AI视觉传感器的分辨率为320×240像素。原点(0, 0)位于左上角,传感器中心位于(160, 120),如下图所示:

下面是所有指令块的列表:
动作 —— 控制 AI 视觉仪的图像流并捕获物体数据。
屏幕上的 AI 视觉查看器 — 启用或禁用机器人屏幕上的实时 AI 视觉画面。
获取对象数据 — 捕获特定对象类型的数据,例如颜色、预训练对象或 AprilTag ID。
设置 — 调整要访问的已检测到的对象。
设置 AI 视觉对象项 — 从检测到的对象列表中选择特定对象。
值 — 返回对象是否存在、分类和属性。
有物体? — 检查机器人是否持有检测到的物体。
AI Vision 对象是否存在? — 返回是否检测到对象。
AI Vision 对象是? — 检查检测到的对象是否与特定分类匹配。
AI Vision 对象是 AprilTag ID 吗? — 检查检测到的 AprilTag ID 是否与特定 ID 匹配。
AI Vision 对象计数 — 返回检测到的对象数量。
AI Vision 对象属性 — 返回详细信息,例如:
行动#
屏幕上的AI视觉查看器#
“屏幕上的 AI 视觉查看器”模块用于启用或禁用机器人屏幕上的实时 AI 视觉画面。启用后,屏幕将显示实时传感器数据,其他图像或文本将无法显示。要显示其他内容,请使用此模块隐藏画面。
AI Vision [show v] viewer on screen
参数 |
描述 |
|---|---|
地位 |
控制机器人屏幕上数据流的显示:
|
示例
when started
[View the AI Vision Sensor's feed for five seconds.]
AI Vision [show v] viewer on screen
wait [5] seconds
AI Vision [hide v] viewer on screen
获取对象数据#
“获取对象数据”模块用于过滤来自 AI 视觉传感器帧的数据。AI 视觉传感器可以检测包含预训练对象、AprilTag ID 或已配置颜色和颜色代码的特征。
必须先在 AI Vision Utility 中配置颜色和颜色代码,然后才能将其与此块一起使用。
该数据集存储的对象按宽度从大到小排序,从索引 0 开始。可以使用 AI Vision 对象属性 块访问每个对象的属性。如果未检测到匹配的对象,则返回空数据集。
get [sports ball v] data from AI Vision
范围 |
描述 |
|---|---|
签名 |
筛选数据集,仅包含给定签名的数据。可用签名包括:
|
示例
when started
[Move forward if a sports ball is detected.]
forever
get [sports ball v] data from AI Vision
if <AI Vision object exists?> then
move [forward v] for [10] [mm v] ▶
色彩签名#
颜色特征码是人工智能视觉传感器可以识别的独特颜色。这些特征码使传感器能够根据物体的颜色来检测和跟踪物体。在人工智能视觉实用程序中配置颜色特征码后,传感器即可识别视野范围内具有该特定颜色的物体。
颜色签名在 获取对象数据 块 中使用,以实时处理和检测彩色对象。

示例
when started
[Display if any objects matching the Red_Box signature is detected.]
forever
set cursor to row [1] column [1] on screen
clear row [1] on screen
[Change the signature to any configured Color Signature.]
get [Red_Box v] data from AI Vision
if <AI Vision object exists?> then
print [Color signature detected!] on screen ▶
颜色代码#
颜色代码是一种结构化的图案,由 2 到 4 个按特定顺序排列的颜色特征组成。在 AI 视觉实用程序中配置好颜色代码后,传感器即可识别预定义的颜色图案。
颜色代码对于识别复杂物体、与游戏元素对齐或为自主导航创建唯一标记特别有用。

示例
when started
[Display if any objects matching the BlueRed code is detected.]
forever
set cursor to row [1] column [1] on screen
clear row [1] on screen
[Change the signature to any configured Color Code.]
get [BlueRed v] data from AI Vision
if <AI Vision object exists?> then
print [Color code detected!] on screen ▶
设置#
设置 AI Vision 对象项#
设置 AI Vision 对象项 块设置要使用数据集中的哪个项。
set AI Vision object item to (1)
参数 |
描述 |
|---|---|
物品 |
数据集中要使用的项目数量。 |
示例
when started
[Display the width of the smallest detected object.]
forever
get [all cargo v] data from AI Vision
clear row [1] on screen
set cursor to row [1] column [1] on screen
if <AI Vision object exists?> then
set AI Vision object item to (AI Vision object count)
print (AI Vision object [width v]) on screen ▶
价值观#
有对象吗?#
has object 块返回一个布尔值,指示机器人当前是否检测到有针对其 Kicker 的对象。
正确——机器人已获得该物体。
错误——机器人没有该物体。
<has [sports ball v]?>
范围 |
描述 |
|---|---|
目的 |
检测机器人踢球者所面对的物体:
|
示例
when started
[Kick when the robot has a sports ball.]
forever
if <has [sports ball v]?> then
kick object [medium v]
AI Vision 对象存在吗?#
AI Vision 对象存在? 模块返回一个布尔值,指示是否在数据集中检测到对象。
正确——数据集包含检测到的对象。
错误——未检测到任何物体。
<AI Vision object exists?>
参数 |
描述 |
|---|---|
该块没有参数。 |
示例
when started
[Move forward if a sports ball is detected.]
forever
get [sports ball v] data from AI Vision
if <AI Vision object exists?> then
move [forward v] for [10] [mm v] ▶
AI视觉的对象是什么?#
AI Vision 对象是? 块返回一个布尔值,指示检测到的对象是否与特定分类匹配。
正确——数据集中的项是特定的对象。
错误——数据集中的项不是特定对象。
<AI Vision object is [sports ball v] ?>
范围 |
描述 |
|---|---|
目的 |
将物品与哪个物体进行比较:
|
示例
when started
[Display if a sports ball is detected.]
forever
get [all cargo v] data from AI Vision
clear row [1] on screen
set cursor to row [1] column [1] on screen
if <AI Vision object exists?> then
if <AI Vision object is [sports ball v] ?> then
print [Sports ball detected!] on screen ▶
wait [0.5] seconds
AI Vision 对象是 AprilTag ID?#
AI Vision 对象是否为 AprilTag ID? 块返回一个布尔值,指示检测到的 AprilTag ID 是否与特定 ID 匹配。
没错——AprilTag ID 就是这个数字。
错误——AprilTag ID 不是数字。
<AI Vision object is AprilTag [1] ?>
参数 |
描述 |
|---|---|
AprilTag ID |
与检测到的 AprilTag 的 ID 号进行比较的数字。 |
AI 视觉对象计数#
AI Vision 对象计数 块以整数形式返回数据集中检测到的对象的数量。
AI Vision object count
参数 |
描述 |
|---|---|
该块没有参数。 |
示例
when started
[Display the amount of sports balls and barrels.]
forever
clear row [1] on screen
set cursor to row [1] column [1] on screen
get [all cargo v] data from AI Vision
if <AI Vision object exists?> then
print (AI Vision object count) on screen ▶
结束
wait [0.5] seconds
AI Vision 对象属性#
使用 获取对象数据块 后存储的每个对象(如下所示)都包含九个属性。
AI Vision object [width v]
某些属性值基于使用获取对象数据块时检测到的物体在 AI 视觉传感器视图中的位置。AI 视觉传感器的分辨率为 320 x 240 像素。

范围 |
描述 |
|---|---|
财产 |
使用被检测对象的哪个属性: |
宽度#
width 返回检测到的物体的宽度,单位为像素,值为 1 到 320 之间的整数。
**注:**像素值是相对于传感器坐标系而言的。请参阅引言中的图表以获取参考。
AI Vision object [width v]

示例
when started
[Move towards a blue barrel until its width is larger than 100 pixels.]
forever
get [blue barrel v] data from AI Vision
if <AI Vision object exists?> then
if <(AI Vision object [width v]) [math_less_than v] [100]> then
move [forward v]
结束
else
stop all movement
高度#
height 返回检测到的物体的高度,单位为像素,值为 1 到 240 之间的整数。
**注:**像素值是相对于传感器坐标系而言的。请参阅引言中的图表以获取参考。
AI Vision object [height v]

示例
when started
[Move towards a blue barrel until its height is larger than 100 pixels.]
forever
get [blue barrel v] data from AI Vision
if <AI Vision object exists?> then
if <(AI Vision object [height v]) [math_less_than v] [100]> then
move [forward v]
结束
else
stop all movement
中心X#
centerX 返回被检测物体中心的 x 坐标,单位为像素,值为 0 到 320 之间的整数。
**注:**像素值是相对于传感器坐标系而言的。请参阅引言中的图表以获取参考。
AI Vision object [centerX v]

示例
when started
[Turn slowly until a blue barrel is centered in front of the robot.]
set turn velocity to [30]%
turn [right v]
forever
get [blue barrel v] data from AI Vision
if <AI Vision object exists?> then
if <[140] [math_less_than v] (AI Vision object [centerX v]) [math_less_than v] [180]> then
stop all movement
中心Y#
centerY 返回被检测物体中心的 y 坐标,单位为像素,值为 0 到 240 之间的整数。
**注:**像素值是相对于传感器坐标系而言的。请参阅引言中的图表以获取参考。
AI Vision object [centerY v]

示例
when started
[Move towards a blue barrel until its center y-coordinate is more than 140 pixels.]
forever
get [blue barrel v] data from AI Vision
if <AI Vision object exists?> then
if <(AI Vision object [centerY v]) [math_less_than v] [140]> then
move [forward v]
结束
else
stop all movement
原点X#
originX 返回被检测物体边界框左上角的 x 坐标,单位为像素,值为 0 到 320 之间的整数。
**注:**像素值是相对于传感器坐标系而言的。请参阅引言中的图表以获取参考。
AI Vision object [originX v]

示例
when started
[Display if an orange barrel is to the left or the right.]
forever
clear row [1] on screen
set cursor to row [1] column [1] on screen
get [orange barrel v] data from AI Vision
if <AI Vision object exists?> then
if <(AI Vision object [originX v]) [math_less_than v] [160]> then
print [To the left!] on screen ▶
else
print [To the right!] on screen ▶
结束
wait [0.5] seconds
原点#
originY 返回被检测物体边界框左上角的 y 坐标,单位为像素,值为 0 到 240 之间的整数。
**注:**像素值是相对于传感器坐标系而言的。请参阅引言中的图表以获取参考。
AI Vision object [originY v]

示例
when started
[Display if an orange barrel is close or far from the robot.]
forever
clear row [1] on screen
set cursor to row [1] column [1] on screen
get [orange barrel v] data from AI Vision
if <AI Vision object exists?> then
if <(AI Vision object [originY v]) [math_less_than v] [80]> then
print [Far!] on screen ▶
else
print [Close!] on screen ▶
结束
wait [0.5] seconds
旋转#
rotation 返回检测到的 AprilTag ID 或颜色代码的朝向(旋转角度),值为 0 到 359 之间的整数,单位为度。
AI Vision object [rotation v]

示例
when started
[Slide left or right depending on how the Color Code is rotated.]
forever
get [Red_Blue v] data from AI Vision
if <AI Vision object exists?> then
if <[50] [math_less_than v] (AI Vision object [rotation v]) [math_less_than v] [100]> then
move [right v]
else if <[270] [math_less_than v] (AI Vision object [rotation v]) [math_less_than v] [330]> then
move [left v]
else
stop all movement
结束
else
stop all movement
轴承#
bearing 以度数为单位,返回物体偏离 AI 视觉仪视野中心的左右程度。值为 0 表示物体位于中心,正值表示物体在右侧,负值表示物体在左侧。
when started
[Keep the blue barrel directly in front of the robot.]
set turn velocity to [40]%
forever
get [blue barrel v] data from AI Vision
if <AI Vision object exists?> then
if <(AI Vision object [bearing v]) [math_greater_than v] [5]> then
turn [right v]
else if <(AI Vision object [bearing v]) [math_less_than v] [-5]> then
turn [left v]
else
stop all movement
标签ID#
tagID 返回检测到的 AprilTag ID 的识别号码,以整数形式表示。
AI Vision object [tagID v]
示例
when started
[Move forward when AprilTag ID 0 is detected.]
forever
get [AprilTag ID 0 v] data from AI Vision
if <AI Vision object exists?> then
move [forward v]
结束
stop all movement