> For the complete documentation index, see [llms.txt](https://docs.convai.com/api-docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-blueprint-reference.md).

# 视觉 Blueprint 参考

Blueprint 可访问的视觉枚举、Environment Webcam 属性、摄像头节点、事件和 Chatbot 集成功能的参考。

Convai Unreal Engine 插件中可通过 Blueprint 访问的视觉接口的完整参考。此处的条目均已对照 `VisionInterface.h`, `ConvaiWebcamBase.h`, `EnvironmentWebcame.h`, `EnvironmentWebcame.cpp`, `ConvaiAudioStreamer.h`以及 `ConvaiAudioStreamer.cpp`.

随插件提供的帧来源是 **环境摄像头** (`UEnvironmentWebcam`）。当前插件没有单独的实体摄像头组件。

### 枚举

#### EVisionState

声明于 `VisionInterface.h`。描述视觉组件的生命周期状态。

| 值           | 显示名称 | 说明                     |
| ----------- | ---- | ---------------------- |
| `Stopped`   | 已停止  | 视觉系统处于非活动状态。不会采集任何帧。   |
| `Starting`  | 正在启动 | 在枚举中定义。随插件提供的实现不会设置此值。 |
| `Capturing` | 正在采集 | 视觉系统处于活动状态，正在采集帧。      |
| `Stopping`  | 正在停止 | 在枚举中定义。随插件提供的实现不会设置此值。 |
| `Paused`    | 已暂停  | 在枚举中定义。随插件提供的实现不会设置此值。 |

在当前随插件提供的流程中， **环境摄像头** 仅设置 `Stopped` 和 `Capturing`.

#### ETextureSourceType

声明于 `VisionInterface.h`。描述由 **获取图像纹理**.

| 值                | 显示名称           | 说明                              |
| ---------------- | -------------- | ------------------------------- |
| `Texture2D`      | Texture2D      | 纹理是一个 `UTexture2D`.             |
| `RenderTarget2D` | RenderTarget2D | 纹理是一个 `UTextureRenderTarget2D`. |

### UConvaiWebcamBase Blueprint 节点

`UConvaiWebcamBase` 是 Convai 视觉组件的抽象基类。以下所有节点均属于 **Convai | 视觉**.

#### 启动

启动组件的采集。在 `UEnvironmentWebcam`中，此操作会验证采集组件和渲染目标，然后将状态设为 `Capturing`.

无输入或输出参数。

#### 停止

停止组件的采集。在 `UEnvironmentWebcam`中，此操作会将状态设为 `Stopped` 并禁用 `CaptureComponent->bCaptureEveryFrame`.

无输入或输出参数。

#### 获取状态

返回组件当前的 `EVisionState` 。 `BlueprintPure`.

| 返回  | 类型             | 说明          |
| --- | -------------- | ----------- |
| 返回值 | `EVisionState` | 当前视觉生命周期状态。 |

#### 设置最大 FPS

设置最大采集帧率（帧/秒）。值 `<= 0` 会被拒绝，并记录为错误。

| 参数     | 类型    | 说明          |
| ------ | ----- | ----------- |
| 最大 FPS | `int` | 要应用的最大 FPS。 |

聊天机器人上传路径会将实际发送速率限制在 `1`–`60` 读取 `GetMaxFPS()`.

#### 获取最大 FPS

返回当前的最大 FPS 设置。 `BlueprintPure`.

| 返回  | 类型    | 说明                   |
| --- | ----- | -------------------- |
| 返回值 | `int` | 当前的最大 FPS。默认值为 `15`. |

#### 获取上次错误消息

返回组件记录的上次错误消息。 `BlueprintPure`.

| 返回  | 类型        | 说明          |
| --- | --------- | ----------- |
| 返回值 | `FString` | 对上次错误的可读描述。 |

#### 获取上次错误代码

返回组件记录的上次错误代码。 `BlueprintPure`。初始值为 `-1`.

| 返回  | 类型    | 说明      |
| --- | ----- | ------- |
| 返回值 | `int` | 数值错误代码。 |

#### 获取图像纹理

返回当前帧纹理及其来源类型。

| 参数     | 类型                   | 方向 | 说明                                       |
| ------ | -------------------- | -- | ---------------------------------------- |
| 纹理来源类型 | `ETextureSourceType` | 输出 | 返回的纹理是否为 `Texture2D` 或 `RenderTarget2D`. |
| 返回值    | `UTexture*`          | 返回 | 当前帧纹理。                                   |

`CaptureRaw`, `CaptureCompressed`, `GetCompressedData`，以及 `IsCompressedDataAvailable` 属于 `IConvaiVisionInterface` ，但不是随附类中的蓝图节点。聊天机器人发送路径会从 C++ 调用 `CaptureRaw()` 。

### UConvaiWebcamBase 事件

#### 帧就绪时

一个 `BlueprintAssignable` 委托，位于 `UConvaiWebcamBase`上。对于 `UEnvironmentWebcam`，当组件处于 `TickComponent()` 期间，且组件状态为 `Capturing` 并且事件已绑定时，它会广播。

若要仅在第一帧运行逻辑，请在绑定的事件中使用布尔标志进行判断。 `FOnFirstFrameCaptured` 位于 `IConvaiVisionInterface` 中，仅供 C++ 使用。

### UEnvironmentWebcam 属性

`UEnvironmentWebcam` 继承自 `UConvaiWebcamBase`。所有属性都位于 **Convai | 视觉**.

在 `UEnvironmentWebcam`:

| 属性                           | 类型                          | 默认值                               | 说明                                                                                                                      |
| ---------------------------- | --------------------------- | --------------------------------- | ----------------------------------------------------------------------------------------------------------------------- |
| `ConvaiRenderTarget`         | `UTextureRenderTarget2D*`   | `null`                            | 组件渲染到的渲染目标。调用 **启动**.                                                                                                   |
| `CaptureComponent`           | `USceneCaptureComponent2D*` | 自动创建为 `EnvironmentSceneCapture2D` | 内部场景捕获组件。构造函数会设置 `bCaptureEveryFrame = false`, `bCaptureOnMovement = false`，以及 `CaptureSource = SCS_FinalToneCurveHDR`. |
| `bCopyPostProcessProperties` | `bool`                      | `false`                           | 启用时，会从世界中找到的第一个 `APostProcessVolume` 复制设置，查找发生在 `BeginPlay`.                                                            |
| `bAutoStartVision`           | `bool`                      | `false`                           | 当 `true`时，会在 **Start** 期间自动调用 `BeginPlay`.                                                                              |

继承自 `UConvaiWebcamBase`:

| 属性               | 类型        | 默认值    | 说明                      |
| ---------------- | --------- | ------ | ----------------------- |
| `Identifier`     | `FString` | `""`   | 可选标签。已发布的运行时路径不会使用此项。   |
| `m_MaxFPS`       | `int`     | `15`   | 最大捕获帧率。通过 **设置最大 FPS**. |
| `bUpdateOnFetch` | `bool`    | `true` | 存储在基类中。已发布的运行时路径不会使用此项。 |

### UEnvironmentWebcam 运行时行为

| 函数                    | 行为                                                                                                                                                                            |
| --------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `BeginPlay()`         | 如果 `bCopyPostProcessProperties` 为 `true`，则复制后期处理设置，然后在 **Start** （如果 `bAutoStartVision` 为 `true`.                                                                             |
| `Start()`             | 如果 `CanStart()` 失败，则返回且不更改状态。否则，将状态设为 `Capturing`，并在需要时将 `ConvaiRenderTarget` 赋给 `CaptureComponent->TextureTarget` ，启用 `bCaptureEveryFrame`，并在已绑定时触发 `OnFirstFrameCaptured` 。 |
| `Stop()`              | 如果以下条件不满足，则直接返回且不更改状态： `CanStop()` 。否则，将状态设为 `Stopped`，禁用 `bCaptureEveryFrame`，并在已绑定时触发 `OnFramesStopped` 。                                                                   |
| `CaptureRaw()`        | 从 `ConvaiRenderTarget` 读取原始 RGBA 字节，并返回渲染目标的宽度和高度。                                                                                                                            |
| `CaptureCompressed()` | 将 `ConvaiRenderTarget` 转换为 JPEG 字节。聊天机器人发送流程使用 `CaptureRaw()`.                                                                                                                |

### 聊天机器人视觉节点

以下节点声明于 `UConvaiAudioStreamer` ，并通过继承显示在 `UConvaiChatbotComponent` 上。类别： **Convai | 视觉**。它们也由 `UConvaiPlayerComponent`继承，但在播放器上返回 `false` ，因为只有聊天机器人会重写 `CanUseVision()`.

#### 设置视觉组件

向聊天机器人注册视觉组件，并替换之前注册的组件（如果有）。

| 参数   | 类型                 | 说明                              |
| ---- | ------------------ | ------------------------------- |
| 视觉组件 | `UActorComponent*` | 任何实现了 `UConvaiVisionInterface`. |

| 返回  | 类型     | 说明                                  |
| --- | ------ | ----------------------------------- |
| 返回值 | `bool` | `true` 如果该组件实现了此接口并已注册； `false` 否则。 |

#### 支持视觉

如果已注册有效的视觉组件，则返回 `true` 。如果未注册任何组件，则在所属的 `Actor` 中查找第一个实现了 `UConvaiVisionInterface`.

| 返回  | 类型     | 说明                                           |
| --- | ------ | -------------------------------------------- |
| 返回值 | `bool` | `true` 当一个有效的 `IConvaiVisionInterface` 组件存在。 |

### 项目设置

#### AlwaysAllowVision

`AlwaysAllowVision` 是 `Config` 上的属性 `UConvaiSettings` ，位于类别 **Convai** ，其属性为 `AdvancedDisplay`。打开 **Edit > Project Settings > Plugins > Convai** 进行更改。

启用后，初始连接设置会使用连接类型 `video`，允许项目在 `BeginPlay`.

之后注册视觉组件。蓝图用户还可以通过 **Is Always Allow Vision Enabled** 读取 `UConvaiUtils` 中的设置（类别为 **Convai | Settings**).

### 后续步骤

{% content-ref url="/pages/cf86fde91936bc6994c59ccac11271cc09e11fea" %}
[视觉使用示例](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-usage-examples.md)
{% endcontent-ref %}

{% content-ref url="/pages/a5aa237a7b13fb2c8d46ff004c1de14a2c4cda2a" %}
[视觉帧源](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-frame-sources.md)
{% endcontent-ref %}

{% content-ref url="/pages/afdaa73f8daaacc42144959e698d777a078e46d3" %}
[自定义视觉组件](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/custom-vision-components.md)
{% endcontent-ref %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-blueprint-reference.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
