人工智能视觉传感器#
介绍#
The VEX IQ AI Vision Sensor can detect and track objects, colors, and AprilTags. This allows the robot to analyze its surroundings, follow objects, and react based on detected visual data.
The AI Vision examples are designed for use with a Basebot equipped with a VEX IQ AI Vision Sensor. In these examples, the sensor is configured with the name AIVision1, which appears in the blocks.
Below is a list of all blocks:
Actions — Capture data from the VEX IQ AI Vision Sensor for a selected signature.
get object data — Captures data for a specific object type, such as colors, pre-trained objects, or AprilTags.
Settings — Choose which object to interact with.
set AI Vision object item — Selects a specific object from the detected object list.
Values — Access and use the captured data.
AI Vision object exists? — Returns whether an object is detected.
AI Vision object count — Returns the number of detected objects.
AI Vision object property — Returns details such as:
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.
行动#
获取对象数据#
The get object data block filters data from the VEX IQ AI Vision Sensor frame. The VEX IQ AI Vision Sensor can detect signatures that include pre-trained objects, AprilTags, or configured colors and color codes.
必须先在 AI Vision Utility 中配置颜色和颜色代码,然后才能将其与此块一起使用。
该数据集存储的对象按宽度从大到小排序,从索引 0 开始。可以使用 AI Vision 对象属性 块访问每个对象的属性。如果未检测到匹配的对象,则返回空数据集。
从 [AIVision 1 v]获取 [SELECT_A_SIG v] 数据
范围 |
描述 |
|---|---|
签名 |
Filters the dataset to only include data of the given signature. Available signatures are:
|
**注意:**要显示 AprilTag 或 AI 分类选项,必须在 AI Vision 实用程序中启用它们的检测。
例子
当开始
[Drive forward if an AprilTag is detected.]
永久循环
从 [AIVision 1 v]获取 [AprilTags v] 数据
如果 <[AIVIsion1 v] 对象存在?> 那么
驱动 [向前 v] [10] [毫米 v] ▶
人工智能分类#
The VEX IQ AI Vision Sensor can detect different objects under certain AI Classifications. Depending on the AI Classification model selected when configuring the VEX IQ AI Vision Sensor in the Devices window, different objects will be detected. The currently available models are:
教室物品
蓝球
绿球
红球
蓝环
绿环
红环
蓝立方
绿立方
红立方
VIQRC 混搭组合
光束
红针
蓝针
橙针
色彩签名#
A Color Signature is a unique color that the VEX IQ 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.
颜色签名用于 获取对象数据 块 中,以实时处理和检测彩色对象。一次最多可配置 7 个颜色签名。
AI 视觉实用程序展示了一个连接的视觉传感器正在检测两个彩色物体。左侧显示实时摄像头画面,左侧为蓝色框,右侧为红色框,每个框都带有白色边框。黑色标签显示其各自的名称、坐标和尺寸。右侧包含颜色签名设置,红色和蓝色框的色调和饱和度范围均有滑块。底部是添加颜色、冻结视频、复制和保存图像的按钮,右下角有一个关闭按钮。](/_static/img/AiVision/color_signatures.png)
例子
当开始
[Display if any objects matching the RED_BOX signature is detected.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[Change the signature to any configured Color Signature.]
从 [AIVision 1 v]获取 [RED_BOX v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
在屏幕上打印 [Color detected!]▶
颜色代码#
A Color Code is a structured pattern made up of 2 to 4 Color Signatures arranged in a specific order. These codes allow the VEX IQ AI Vision Sensor to recognize predefined patterns of colors.
颜色代码对于识别复杂物体、与游戏元素对齐或为自主导航创建独特标记非常有用。一次最多可配置 8 个颜色代码。
AI Vision Utility 界面显示一个已连接的视觉传感器正在检测两个相邻的物体,左侧为蓝色框,右侧为红色框,它们被组合成一个标记为 BlueRed 的白色边界框。检测信息包括角度 (A:11°)、坐标 (X:143, Y:103)、宽度 (W:233) 和高度 (H:108)。右侧面板列出了三个颜色特征:Red_Box、Blue_Box 和 BlueRed,并可调整色调和饱和度范围。BlueRed 特征结合了 Blue_Box 和 Red_Box。视频源下方是标有“冻结视频”、“复制图像”、“保存图像”和“关闭”的按钮。](/_static/img/AiVision/color_code.png)
例子
当开始
[Display if any objects matching the RED_BLUE code is detected.]
永久循环
在屏幕上设定光标至 [1] 行 [1] 列
清除屏幕第 [1] 行
[Change the signature to any configured Color Code.]
从 [AIVision 1 v]获取 [RED_BLUE v] 数据
如果 <[AIVIsion1 v] 对象存在?> 那么
在屏幕上打印 [Code detected!]▶
设置#
设置 AI Vision 对象项#
设置 AI Vision 对象项 块设置要使用数据集中的哪个项。
设定 [AIVision 1 v] 对象标号为 (1)
参数 |
描述 |
|---|---|
物品 |
数据集中要使用的项目数量。 |
例子
当开始
[Display the largest detected AprilTag ID.]
永久循环
从 [AIVision 1 v]获取 [AprilTags v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[AIVision 1 v] 对象存在?> 那么
设定 [AIVision 1 v] 对象标号为 ([AIVision 1 v]object count)
在屏幕上打印 ([AIVision 1 v] 对象 [tagID v])▶
价值观#
AI Vision 对象存在吗?#
AI Vision 对象存在 块返回一个布尔值,指示是否在数据集中检测到任何对象。
True — The dataset includes a detected object.
False — The dataset does not include any detected objects.
<[AIVision 1 v] 对象存在?>
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Drive forward if an object is detected.]
永久循环
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
驱动 [向前 v] [10] [毫米 v] ▶
AI 视觉对象计数#
AI Vision 对象计数 块以整数形式返回数据集中检测到的对象的数量。
([AIVision 1 v] 对象数目)
参数 |
描述 |
|---|---|
该块没有参数。 |
例子
当开始
[Display the total amount of cubes, rings, and balls.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
在屏幕上打印 ([AIVision 1 v] 对象数目)▶
结束
等待 [0.5] 秒
AI Vision 对象属性#
使用 获取对象数据块 后存储的每个对象(如下所示)包含九个属性。
([AIVision 1 v] 对象 [宽 v])
Some property values are based off of the detected object’s position in the VEX IQ AI Vision Sensor’s view at the time that the Get object data block was used. The VEX IQ AI Vision Sensor has a resolution of 320 by 240 pixels.
范围 |
描述 |
|---|---|
财产 |
Which property of the detected object to use: |
宽度#
width 以像素为单位返回检测到的对象的宽度,范围是 1 到 320 之间的整数。
([AIVision 1 v] 对象 [宽 v])
例子
当开始
[Drive towards an object until its width is larger than 100 pixels.]
永久循环
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [宽 v]) [math_less_than v] [100]> 那么
驱动 [向前 v]
结束
否则
驱动停止
高度#
高度以像素为单位返回检测到的物体的高度,范围是 1 到 240 之间的整数。
([AIVision 1 v] 对象 [高 v])
例子
当开始
[Drive towards an object until its height is larger than 100 pixels.]
永久循环
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [高 v]) [math_less_than v] [100]> 那么
驱动 [向前 v]
结束
否则
驱动停止
中心X#
centerX 以像素为单位返回检测到的物体中心的 x 坐标,为 0 到 320 之间的整数。
([AIVision 1 v] 对象 [中心X坐标 v])
例子
当开始
[Turn slowly until an object is centered in front of the robot.]
设定转向速度为 [30] [% v]
[右 v] 转
永久循环
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[140] [math_less_than v] ([AIVision 1 v] 对象 [中心X坐标 v]) [math_less_than v] [180]> 那么
驱动停止
中心Y#
centerY 以像素为单位返回检测到的物体中心的 y 坐标,为 0 到 240 之间的整数。
([AIVision 1 v] 对象 [中心Y坐标 v])
例子
当开始
[Drive towards an object until its center y-coordinate is more than 140 pixels.]
永久循环
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [中心Y坐标 v]) [math_less_than v] [140]> 那么
驱动 [向前 v]
结束
否则
驱动停止
角度#
angle 以 0 至 359 度之间的整数形式返回检测到的颜色代码或 AprilTag 的方向。
([AIVision 1 v] 对象 [夹角 v])
例子
当开始
[Slide left or right depending on how the Color Code is rotated.]
永久循环
从 [AIVision 1 v]获取 [RED_BLUE v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[50] [math_less_than v] ([AIVision 1 v] 对象 [夹角 v]) [math_less_than v] [100]> 那么
驱动 [右 v]
否则如果 <[270] [math_less_than v] ([AIVision 1 v] 对象 [夹角 v]) [math_less_than v] [330]> 那么
驱动 [左 v]
否则
驱动停止
结束
否则
驱动停止
原点X#
originX 以像素为单位返回检测到的对象边界框左上角的 x 坐标,为 0 到 320 之间的整数。
([AIVision 1 v] 对象 [原点X v])
例子
当开始
[Display if an object is to the left or the right.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [原点X v]) [math_less_than v] [160]> 那么
在屏幕上打印 [To the left!]▶
否则
在屏幕上打印 [To the right!]▶
结束
等待 [0.5] 秒
原点Y#
originY 以像素为单位返回检测到的对象边界框左上角的 y 坐标,为 0 到 240 之间的整数。
([AIVision 1 v] 对象 [原点Y v])
例子
当开始
[Display if an object is close or far from the robot.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 [AIVision 1 v]获取 [AI Classifications v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [原点Y v]) [math_less_than v] [80]> 那么
在屏幕上打印 [Far!]▶
否则
在屏幕上打印 [Close!]▶
结束
等待 [0.5] 秒
标签ID#
tagID 以整数形式返回检测到的 AprilTag 的识别号。
([AIVision 1 v] 对象 [tagID v])
例子
当开始
[Drive forward when AprilTag ID 0 is detected.]
永久循环
从 [AIVision 1 v]获取 [AprilTags v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <([AIVision 1 v] 对象 [tagID v]) [math_equal v] [0]> 那么
驱动 [向前 v]
否则
驱动停止
结束
等待 [0.5] 秒
AI视觉的对象是什么?#
AI Vision 对象是? 块返回一个布尔值,指示检测到的对象是否与特定分类匹配。
True — The item in the dataset is the specific object.
False — The item in the dataset is not the specific object.
<[AIVision1 v] object is [BlueBall v]?>
范围 |
描述 |
|---|---|
目的 |
要将该物品与哪个AI分类进行比较。 |
例子
当开始
[Display if a Blue Cube is detected.]
永久循环
从 [AIVision 1 v]获取 [AI Classifications v] 数据
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[AIVision1 v] object is [BlueCube v]?> 那么
在屏幕上打印 [Cube detected!]▶
等待 [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.
<[AIVision 1 v] 对象是 AprilTag [1] 吗?>
参数 |
描述 |
|---|---|
四月标签号码 |
与检测到的 AprilTag 的 ID 号进行比较的数字。 |
例子:
当开始
[Report if AprilTag ID 3 is detected.]
永久循环
清屏
在屏幕上设定光标至 [1] 行 [1] 列
从 [AIVision 1 v]获取 [AprilTags v] 数据
如果 <[AIVision 1 v] 对象存在?> 那么
如果 <[AIVision 1 v] 对象是 AprilTag [3] 吗?> 那么
在屏幕上打印 [That is 3!]▶
否则
在屏幕上打印 [That isn't 3!]▶
结束
结束
等待 [0.1] 秒