人工智能视觉#
介绍#
VEX AIM 编程机器人的 AI 视觉传感器可以检测并追踪物体、颜色和 AprilTag。这使得机器人能够分析周围环境、跟踪物体并根据检测到的视觉数据做出反应。以下是所有可用模块的列表:
操作——控制 AI Vision 馈送并捕获对象数据。
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 AprilTags.
设置——调整访问哪些检测到的对象。
set AI Vision object item – Selects a specific object from the detected object list.
值——返回对象的存在、分类和属性。
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 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 图像。启用后,屏幕将显示实时传感器数据,并阻止显示其他图像或文本。如需显示其他内容,请使用此模块隐藏图像。
屏幕上的AI视觉 [显示 v] 查看器
参数 |
描述 |
---|---|
地位 |
Controls the display of the data feed on the robot’s screen:
|
例子
当开始 :: hat events
[查看 AI 视觉传感器的反馈五秒钟.]
屏幕上的AI视觉 [显示 v] 查看器
等待 [5] 秒
屏幕上的AI视觉 [隐藏 v] 查看器
获取对象数据#
获取对象数据 模块会过滤来自 AI 视觉传感器框架的数据。AI 视觉传感器可以检测包含预训练对象、AprilTag 或已配置颜色和颜色代码的签名。
必须先在 AI Vision Utility 中配置颜色和颜色代码,然后才能使用此方法。
The dataset stores objects ordered from largest to smallest by width, starting at index 0. Each object’s properties can be accessed using AI Vision object property block. An empty dataset is returned if no matching objects are detected.
获得 AI 视觉仪 [运动球 v] 数据
范围 |
描述 |
---|---|
签名 |
Filters the dataset to only include data of the given signature. Available signatures are:
|
例子
当开始 :: hat events
[如果检测到运动球,则向前移动.]
永久循环
获得 AI 视觉仪 [运动球 v] 数据
如果 <AI 视觉仪对象存在?> 那么
移动 [正 v] [10] [mm v] ▶
色彩签名#
颜色特征是 AI 视觉传感器能够识别的独特颜色。这些特征使传感器能够根据物体的颜色进行检测和跟踪。配置颜色特征后,传感器便可以识别视野范围内具有该特定颜色的物体。
Color Signatures are used in the Get object data block to process and detect colored objects in real-time.
例子
当开始 :: hat events
[检测到与红框特征匹配的对象显示.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[将签名更改为任何已配置的彩色签名.]
获得 AI 视觉仪 [运动球 v] 数据
如果 <AI 视觉仪对象存在?> 那么
打印 [检测到颜色特征!] 在屏幕 ▶
颜色代码#
颜色代码是由 2 到 4 个按特定顺序排列的颜色特征组成的结构化模式。这些代码使 AI 视觉传感器能够识别预定义的颜色模式。
颜色代码对于识别复杂物体、与游戏元素对齐或为自主导航创建唯一标记特别有用。
例子
当开始 :: hat events
[检测到与蓝红代码匹配的物体的显示.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[将签名更改为任何配置的颜色代码.]
获得 AI 视觉仪 [BlueRed v] 数据
如果 <AI 视觉仪对象存在?> 那么
打印 [检测到颜色代码!] 在屏幕 ▶
设置#
设置 AI Vision 对象项#
设置 AI Vision 对象项 块设置要使用数据集中的哪个项。
设定 AI 视觉仪对象标号为 (1)
参数 |
描述 |
---|---|
物品 |
数据集中要使用的项目数量。 |
例子
当开始 :: hat events
[显示检测到的最大 AprilTag ID.]
永久循环
获得 AI 视觉仪 [四月标签 v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <AI 视觉仪对象存在?> 那么
设定 AI 视觉仪对象标号为 (AI 视觉仪对象数目)
打印 (AI 视觉仪对象 [标签ID v]) 在屏幕 ▶
价值观#
有对象吗?#
has object 块返回一个布尔值,指示机器人当前是否在其 Kicker 处检测到物体。
True – The robot has the object.
False – The robot does not have the object.
<[运动球 v] 存在?>
范围 |
描述 |
---|---|
目的 |
The object to detect against the robot’s kicker:
|
例子
当开始 :: hat events
[当机器人有运动球时踢球.]
永久循环
如果 <[运动球 v] 存在?> 那么
[中 v] 踢出对象
AI Vision 对象存在吗?#
AI Vision 对象存在返回一个布尔值,指示是否在数据集中检测到任何对象。
True – The dataset includes a detected object.
False – The dataset does not include any detected objects.
<AI 视觉仪对象存在?>
参数 |
描述 |
---|---|
该块没有参数。 |
例子
当开始 :: hat events
[如果检测到运动球,则向前移动.]
永久循环
获得 AI 视觉仪 [运动球 v] 数据
如果 <AI 视觉仪对象存在?> 那么
移动 [正 v] [10] [mm 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] ?>
范围 |
描述 |
---|---|
目的 |
Which object to compare the item to:
|
例子
当开始 :: hat events
[如果检测到运动球则显示.]
永久循环
获得 AI 视觉仪 [所有货物 v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <AI 视觉仪对象存在?> 那么
如果 <AI 视觉仪对象为 [运动球 v] ?> 那么
打印 [检测到运动球!] 在屏幕 ▶
等待 [0.5] 秒
AI Vision 对象是 AprilTag ID?#
AI Vision 对象是 AprilTag ID? 块返回一个布尔值,指示检测到的 AprilTag 是否与特定 ID 匹配。
True – The AprilTag ID is the number.
False – The AprilTag ID is not the number.
<AI 视觉仪检测到 AprilTag [1] ?>
参数 |
描述 |
---|---|
四月标签号码 |
与检测到的 AprilTag 的 ID 号进行比较的数字。 |
当开始 :: hat events
[如果检测到 AprilTag ID 3 则报告.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
获得 AI 视觉仪 [四月标签 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <AI 视觉仪检测到 AprilTag [3] ?> 那么
打印 [即 3!] 在屏幕 ▶
否则
打印 [那不是 3!] 在屏幕 ▶
结束
结束
等待 [0.1] 秒
AI 视觉对象计数#
AI Vision 对象计数 块以整数形式返回数据集中检测到的对象的数量。
AI 视觉仪对象数目
参数 |
描述 |
---|---|
该块没有参数。 |
例子
当开始 :: hat events
[显示运动球和桶的数量.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
获得 AI 视觉仪 [所有货物 v] 数据
如果 <AI 视觉仪对象存在?> 那么
打印 [AI 视觉仪对象数目] 在屏幕 ▶
结束
等待 [0.5] 秒
AI Vision 对象属性#
There are nine properties that are included with each object (shown below) stored after the Get object data block is used.
AI 视觉仪对象 [宽 v]
某些属性值基于使用获取对象数据块时检测到的物体在 AI 视觉传感器视图中的位置。AI 视觉传感器的分辨率为 240 x 320 像素。
范围 |
描述 |
---|---|
财产 |
Which property of the detected object to use: |
宽度#
width returns the width of the detected object in pixels as an integer from 1 to 320.
AI 视觉仪对象 [宽 v]
例子
当开始 :: hat events
[向蓝色桶移动,直到其宽度大于 100 像素.]
永久循环
获得 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]
例子
当开始 :: hat events
[向蓝色桶移动,直到其高度大于 100 像素.]
永久循环
获得 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]
例子
当开始 :: hat events
[慢慢转动,直到蓝色桶位于机器人前方中央.]
设定转向速度为 [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]
例子
当开始 :: hat events
[向蓝色桶移动,直到其中心 y 坐标超过 140.]
永久循环
获得 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]
例子
当开始 :: hat events
[显示橙色桶是在左边还是右边.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
获得 AI 视觉仪 [橙色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [原点X v]) [math_less_than v] [160]> 那么
打印 [向左转!] 在屏幕 ▶
否则
打印 [向右!] 在屏幕 ▶
结束
等待 [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]
例子
当开始 :: hat events
[显示橙色桶距离机器人是否较近或较远.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
获得 AI 视觉仪 [橙色桶 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [原点Y v]) [math_less_than v] [80]> 那么
打印 [远的!] 在屏幕 ▶
否则
打印 [关闭!] 在屏幕 ▶
结束
等待 [0.5] 秒
旋转#
rotation returns the orientation of the detected AprilTag or Color Code as an integer in degrees from 0 to 359.
AI 视觉仪对象 [旋转 v]
例子
当开始 :: hat events
[根据颜色代码的旋转方式向左或向右滑动.]
永久循环
获得 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.
当开始 :: hat events
[将蓝色桶放在机器人正前方.]
设定转向速度为 [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 as an integer.
AI 视觉仪对象 [标签ID v]
例子
当开始 :: hat events
[当检测到 AprilTag ID 0 时向前移动.]
永久循环
获得 AI 视觉仪 [四月标签 v] 数据
如果 <AI 视觉仪对象存在?> 那么
如果 <(AI 视觉仪对象 [标签ID v]) [math_equal v] [0]> 那么
移动 [正 v]
结束
停止移动