人工智能视觉#

介绍#

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.

Values — Return object presence, classification, and properties.

行动#

AI 视觉查看器#

AI Vision 查看器 模块用于在机器人屏幕上启用或禁用实时 AI Vision 图像。启用后,屏幕将显示实时传感器数据,并阻止显示其他图像或文本。如需显示其他内容,请使用此模块隐藏图像。

显示或隐藏 AI Vision 仪表板堆栈块。#
[显示 v]AI 视觉仪在屏幕上的查看器

参数

描述

地位

Controls the display of the data feed on the robot’s screen:

  • show — Displays the data feed.
  • hide — Removes the data feed from the screen.

例子

一组块,以“启动时”块开头,后跟注释块,内容为“查看 AI 视觉传感器的 feed 五秒钟”。“显示 AI 视觉仪表板”块显示 feed,然后“等待”块暂停执行五秒钟。等待结束后,“隐藏 AI 视觉仪表板”块将从视图中移除 feed。#
当开始
[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:

  • sports ball
  • orange barrel
  • blue barrel
  • AIM robot
  • AprilTag ID 0
  • AprilTag ID 1
  • AprilTag ID 2
  • AprilTag ID 3
  • AprilTag ID 4
  • all cargo — Sports balls and all barrels
  • NAME — A color or color code where NAME is the name configured in the AI Vision Utility

例子

一组以“启动时”块开头的块,后面跟着一个注释块,注释块内容为“如果检测到运动球,则向前移动”。“拍摄 AI 视觉快照”块用于捕捉运动球的图像。然后,“如果”块检查是否存在 AI 视觉对象。如果存在,则“向前移动”块将机器人向前移动 10 毫米。#
当开始
[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.

AI 视觉实用程序展示了一个连接的视觉传感器正在检测两个彩色物体。左侧显示实时摄像头画面,左侧为蓝色框,右侧为红色框,每个框都带有白色边框。黑色标签显示其各自的名称、坐标和尺寸。右侧包含颜色签名设置,红色和蓝色框的色调和饱和度范围均有滑块。底部是添加颜色、冻结视频、复制和保存图像的按钮,右下角有一个关闭按钮。

例子

当开始
[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.

颜色代码对于识别复杂物体、与游戏元素对齐或为自主导航创建唯一标记特别有用。

AI Vision Utility 界面显示一个已连接的视觉传感器正在检测两个相邻的物体,左侧为蓝色框,右侧为红色框,它们被组合成一个标记为 BlueRed 的白色边界框。检测信息包括角度 (A:11°)、坐标 (X:143, Y:103)、宽度 (W:233) 和高度 (H:108)。右侧面板列出了三个颜色特征:Red_Box、Blue_Box 和 BlueRed,并可调整色调和饱和度范围。BlueRed 特征结合了 Blue_Box 和 Red_Box。视频源下方是标有“冻结视频”、“复制图像”、“保存图像”和“关闭”的按钮。

例子

当开始
[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 Vision 对象项堆栈块。#
设定 AI 视觉仪对象标号为 (1)

参数

描述

物品

数据集中要使用的项目数量。

例子

A stack of blocks that begins with a when started block, followed by a comment block reading Display the largest detected AprilTag ID. Inside a forever loop, a take a AI Vision snapshot block captures an image of AprilTag IDs. An if block checks if an AI Vision object exists. If true, a set AI Vision object item block assigns the object count to a variable, and a print block displays the tag ID of the detected object on the screen.#
当开始
[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.

显示或隐藏 AI Vision 仪表板堆栈块。#
<有 [运动球 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 Vision对象存在布尔块。#
<AI 视觉仪对象存在?>

参数

描述

该块没有参数。

例子

一组块,以“启动时”块开头,后跟注释块“检测到球时向前移动”。“拍摄 AI 视觉快照”块用于捕捉运动球的图像。“如果”块用于检查 AI 视觉对象是否存在。如果存在,则“向前移动”块将机器人向前移动 10 毫米。#
当开始
[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 Vision AI分类是对象布尔块。#
<AI 视觉仪对象为 [运动球 v]?>

范围

描述

目的

将物品与哪个物体进行比较:

  • 运动球
  • 橙色桶
  • 蓝色桶
  • AIM 机器人

例子

一组块,以“启动时”块开头,后跟注释块,内容为“如果检测到运动球则显示”。在一个永久循环中,一个“拍摄 AI 视觉快照”块使用 AI 分类捕获图像。屏幕被清空,光标被设置到第 1 行第 1 列。一个“如果”块检查 AI 视觉对象是否存在,如果存在,则另一个“如果”块验证分类是否为运动球。如果存在,则打印块在屏幕上显示“检测到球!”,然后是一个等待块,暂停 0.5 秒,然后重复该过程。#
当开始
[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.

The AI Vision detected AprilTag ID is Boolean block.#
<AI 视觉仪检测到 AprilTag [1] ?>

参数

描述

AprilTag ID

与检测到的 AprilTag 的 ID 号进行比较的数字。

AI 视觉对象计数#

AI Vision 对象计数 块以整数形式返回数据集中检测到的对象的数量。

设置 AI Vision 对象项堆栈块。#
AI 视觉仪对象数目

参数

描述

该块没有参数。

例子

当开始
[Display the amount of sports balls and barrels.]
永久循环
清除屏幕第 [1] 行
在屏幕上设定光标至 [1] 行 [1] 列
从 AI 视觉仪获取 [所有货物 v] 数据
如果 <AI 视觉仪对象存在?> 那么
在屏幕上打印 (AI 视觉仪对象数目)▶
结束
等待 [0.5] 秒

AI Vision 对象属性#

使用 获取对象数据 后存储的每个对象(如下所示)都包含九个属性。

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 Vision 对象属性堆栈块,其参数设置为宽度。#
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 Vision 对象属性堆栈块,其参数设置为高度。#
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 Vision 对象属性堆栈块,其参数设置为 centerX。#
AI 视觉仪对象 [中心X坐标 v]

带有橙色条纹的蓝色桶位于框架中央,周围环绕着黑色边界框。一条垂直的红色虚线从框架顶部延伸至边界框的中心,指示中心的 X 坐标。

例子

当开始
[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 Vision 对象属性堆栈块,其参数设置为 centerY。#
AI 视觉仪对象 [中心Y坐标 v]

带有橙色条纹的蓝色桶位于框架中央,周围环绕着黑色边界框。一条水平红色虚线从框架左侧延伸至边界框中心,表示中心的 Y 坐标。

例子

当开始
[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 Vision 对象属性堆栈块,其参数设置为 originX。#
AI 视觉仪对象 [原点X v]

带有橙色条纹的蓝色桶位于框架中央,周围环绕着黑色边界框。一条垂直的红色虚线从框架顶部延伸到边界框的左边缘,表示边界框原点的 X 坐标。

例子

当开始
[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 Vision 对象属性堆栈块,其参数设置为 originY。#
AI 视觉仪对象 [原点Y v]

带有橙色条纹的蓝色桶位于框架中央,周围环绕着黑色边界框。一条水平红色虚线从框架左侧延伸至边界框顶部边缘,表示边界框原点的 Y 坐标。

例子

当开始
[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 Vision 对象属性堆栈块,其参数设置为旋转。#
AI 视觉仪对象 [旋转 v]

相机界面显示一个垂直堆叠的物体,上半部分为蓝色,下半部分为红色,位于画面中央。物体下方的标签为“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 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.

settings settings
当开始
[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 Vision 对象属性堆栈块,其参数设置为 tagID。#
AI 视觉仪对象 [tagID v]

例子

当开始
[Move forward when AprilTag ID 0 is detected.]
永久循环
从 AI 视觉仪获取 [AprilTag ID 0 v] 数据
如果 <AI 视觉仪对象存在?> 那么
移动 [向前 v]
结束
停止移动