人工智能视觉#
介绍#
AI 视觉传感器可以检测并追踪物体、颜色和 AprilTag。这使得机器人能够分析周围环境、跟踪物体,并根据检测到的视觉数据做出反应。
For the examples below, the configured AI Vision Sensor will be named ai_vision_1, and the configured Color Signature objects, such as RED_BOX, will be used in all subsequent examples throughout this API documentation when referring to AiVision class methods.
以下是所有方法的列表:
Getters – 从 AI 视觉传感器获取数据。
take_snapshot– Captures data for a specific Signature.installed– Whether the AI Vision Sensor is connected to the EXP Brain.
Properties – Object data returned from take_snapshot.
.exists– Whether the object exists in the current detection as a Boolean..width– Width of the detected object in pixels..height– Height of the detected object in pixels..centerX– X position of the object’s center in pixels..centerY– Y position of the object’s center in pixels..angle– Orientation of the Color Code in degrees..originX– X position of the object’s top-left corner in pixels..originY– Y position of the object’s top-left corner in pixels..id– Classification or tag ID of the object..score– Confidence score for AI Classifications (1–100).
构造函数——手动初始化和配置传感器。
拍摄快照#
take_snapshot filters the data from the AI Vision Sensor’s frame to return a tuple. The AI Vision Sensor can detect configured Color Signatures and Color Codes, AI Classifications, and AprilTags.
必须先在 Vision Utility 中配置 颜色签名 和 颜色代码,然后才能使用此方法。
该元组存储的对象按宽度从大到小排序,从索引 0 开始。每个对象的 属性 可以通过其索引访问。如果未检测到匹配的对象,则返回一个空元组。
Usage:
ai_vision_1.take_snapshot(SIGNATURE)
参数 |
描述 |
|---|---|
|
What signature to get data of.
|
|
可选。设置可返回的最大对象数,范围为 1 至 24(默认值:8)。 |
# Example coming soon
AI Classifications#
AI 视觉传感器可以检测特定 AI 分类下的不同物体。根据在“设备”窗口中配置 AI 视觉传感器时选择的 AI 分类模型,可以检测到不同的物体。目前可用的模型包括:
课堂元素
身份证号码 |
人工智能分类 |
|---|---|
0 |
|
1 |
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
V5RC 高额桌
|:——————:|–|
| ID Number | AI Classification |
| 0 | MOBILE_GOAL |
| 1 | RED_RING |
| 2 | BLUE_RING |
V5RC 后推
|:——————:|–|
| ID Number | AI Classification |
| 0 | BLUE_BLOCK |
| 1 | RED_BLOCK |
# Example coming soon
Color Signatures#
A Color Signature is a unique color that the AI Vision Sensor can recognize. These signatures allow the AI Vision 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. Color signatures are used with take_snapshot to process and detect colored objects in real-time.
In order to use a configured Color Signature in a project, its name must be the name of the sensor, two underscores, and then the Color Signature’s name. For example: ai_vision_1__RED_BOX.
# Example coming soon
Color Codes#
颜色代码是由按特定顺序排列的颜色特征组成的结构化模式。这些代码使AI视觉传感器能够识别预定义的颜色模式。颜色代码可用于识别复杂物体或为自主导航创建独特的标记。
In order to use a configured Color Code in a project, its name must be the name of the sensor, two underscores, and then the Color Code’s name. For example: ai_vision_1__BOX_CODE.
# Example coming soon
已安装#
installed returns a Boolean indicating whether the AI Vision Sensor is currently connected to the EXP Brain.
True– The AI Vision Sensor is connected to the EXP Brain.False– The AI Vision Sensor is not connected to the EXP Brain.
Usage:
ai_vision_1.installed()
参数 |
描述 |
|---|---|
该方法没有参数。 |
# Display a message if the AI Vision Sensor is connected
if ai_vision_1.installed():
brain.screen.print("Installed!")
特性#
There are ten properties that are included with each object stored in a tuple after take_snapshot is used.
Some property values are based off of the detected object’s position in the AI Vision Sensor’s view at the time that take_snapshot was used. The AI Vision Sensor has a resolution of 320 by 240 pixels.
.exists#
.exists returns a Boolean indicating if the index exists in the tuple or not.
True– The index exists.False– The index does not exist.
# Example coming soon
.width#
.width returns the width of the detected object in pixels, which is an integer between 1 and 320.
# Example coming soon
.height#
.height returns the height of the detected object in pixels, which is an integer between 1 and 240.
# Example coming soon
.centerX#
.centerX returns the x-coordinate of the detected object’s center in pixels, which is an integer between 0 and 320.
# Example coming soon
.centerY#
.centerY returns the y-coordinate of the detected object’s center in pixels, which is an integer between 0 and 240.
# Example coming soon
.angle#
.angle returns the orientation of the detected Color Code or AprilTag in degrees, which is an integer between 0 and 360.
# Example coming soon
.originX#
.originX returns the x-coordinate of the top-left corner of the detected object’s bounding box in pixels, which is an integer between 0 and 320.
# Example coming soon
.originY#
.originY returns the y-coordinate of the top-left corner of the detected object’s bounding box in pixels, which is an integer between 0 and 240.
# Example coming soon
.id#
.id returns the ID of the detected AI Classification or AprilTag as an integer.
对于 AI 分类,请参阅 AI 分类 表中对应的 ID。
对于 AprilTag,.id 属性表示检测到的 AprilTag 的 ID 号,范围是 0 到 36。对于 AI 分类,id 对应于预定义的 id,如下所示。
# Example coming soon
.score#
.score returns the confidence score of the detected AI Classification as an integer between 1 and 100.
# Example coming soon
构造函数#
Constructors are used to manually create AiVision, Colordesc, and Codedesc objects, which are necessary for configuring the AI Vision Sensor outside of VEXcode.
AI Vision Sensor#
AiVision creates an AI Vision Sensor.
用法
Vision(port, sigs)
参数 |
描述 |
|---|---|
|
AI 视觉传感器连接到哪个智能端口,从 1 到 12。 |
|
Optional. The name of one or more signatures:
|
例子
# Example coming soon
Color Signature#
Colordesc creates a Color Signature. Up to seven different Color Signatures can be stored on an AI Vision Sensor at once.
用法:
Colordesc(index, uMin, uMax, uMean, vMin, vMax, vMean, rgb, type)
范围 |
描述 |
|---|---|
|
The |
|
The value from |
|
The value from |
|
The value from |
|
The value from |
|
The value from |
|
The value from |
|
The value from |
|
The value from |
要获取创建颜色签名的值,请转到 Vision Utility。配置颜色签名后,从配置窗口复制参数值。
例子
# Example coming soon
Color Code#
Codedesc creates a Color Code. It requires at least two already defined Color Signatures in order to be used. Up to eight different Color Codes can be stored on a Vision Sensor at once.
用法:
Codedesc(sig1, sig2, sig3, sig4, sig5)
范围 |
描述 |
|---|---|
|
先前创建的 颜色签名。 |
|
先前创建的 颜色签名。 |
|
可选。 之前创建的 颜色签名。 |
|
可选。 之前创建的 颜色签名。 |
|
可选。 之前创建的 颜色签名。 |
例子
# Example coming soon