> 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-frame-sources.md).

# 视觉帧源

配置内置的 Environment Webcam 帧源，创建其渲染目标，并在运行时选择活动视觉组件。

帧源是聊天机器人上的一个组件 `Actor` 它实现了 `IConvaiVisionInterface`。 `ConvaiVisionBase` 模块随附 **环境摄像头** (`UEnvironmentWebcam`），用于通过 `USceneCaptureComponent2D`.

如果你是首次设置视觉功能，请先完成 [视觉快速入门](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-quick-start.md) 。完成初始设置后，可使用本页配置帧源。

### 内置帧源

**环境摄像头** 会显示在组件选择器中，名称为 **环境摄像头**。它会从组件变换位置捕获场景，将画面渲染到 `UTextureRenderTarget2D`，并向聊天机器人提供帧数据。

#### 环境摄像头的属性

| 属性                           | 类型                          | 默认值     | 说明                                                     |
| ---------------------------- | --------------------------- | ------- | ------------------------------------------------------ |
| `ConvaiRenderTarget`         | `UTextureRenderTarget2D*`   | `null`  | 组件捕获画面所用的渲染目标。在 **Start** 进入 `Capturing`.              |
| `CaptureComponent`           | `USceneCaptureComponent2D*` | 自动创建    | 内部场景捕获组件，名称为 `EnvironmentSceneCapture2D`.              |
| `bCopyPostProcessProperties` | `bool`                      | `false` | 在 `APostProcessVolume` 期间，复制运行时在世界中找到的第一个 `BeginPlay`. |
| `bAutoStartVision`           | `bool`                      | `false` | 调用 **Start** 期间 `BeginPlay` 启用后。                       |

#### 从 UConvaiWebcamBase 继承的属性

| 属性               | 类型        | 默认值    | 说明                                        |
| ---------------- | --------- | ------ | ----------------------------------------- |
| `Identifier`     | `FString` | `""`   | 存储在组件上的可选标签。随附运行时路径不会使用此标签。               |
| `m_MaxFPS`       | `int`     | `15`   | “细节”面板中显示的最大捕获 FPS **细节** 面板为 **最大 FPS**. |
| `bUpdateOnFetch` | `bool`    | `true` | 存储在基类中。随附的运行时路径不会使用此属性。                   |

完整的属性和节点列表，请参阅 [Vision Blueprint 参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-blueprint-reference.md) 。

### 渲染目标要求

**Environment Webcam** 不会进入 `Capturing` ，除非已将 `UTextureRenderTarget2D` 分配给 **Convai Render Target**.

建议的创建方式：

| 设置     | 值                     |
| ------ | --------------------- |
| 宽度     | `512`                 |
| 高度     | `512`                 |
| 渲染目标格式 | `RTF_RGBA8`           |
| 清除颜色   | `FLinearColor::Black` |

在 **内容浏览器** 中选择 **Convai > Vision Render Target** （当前插件版本中的上下文菜单标签）来创建资源；或者创建标准的 `TextureRenderTarget2D` 并手动设置为相同的值。

### 开始和停止捕获

调用 **Start** ，使 **Environment Webcam** 开始捕获。该组件会验证 `CaptureComponent` 和 **Convai Render Target**，将状态设为 `Capturing`，启用内部捕获组件上的 `bCaptureEveryFrame` ，并开始将场景帧写入渲染目标。

调用 **Stop** ，将状态设为 `Stopped` 并禁用 `bCaptureEveryFrame`.

手动方式的替代方案 **开始** 接线：

* 在 `bAutoStartVision` 中启用 **详细信息** 面板，以便在 **开始** 期间自动调用 `BeginPlay`.
* 请遵循 **事件 BeginPlay → 开始** 中的模式 [Vision 快速入门](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-quick-start.md).

### 在运行时更改活动视觉组件

`UConvaiChatbotComponent` 会自动发现其所在 `Actor` 上第一个实现了 `UConvaiVisionInterface`的组件。若要显式选择其他来源，请调用 **设置视觉组件** 并将所需组件传入聊天机器人。

```
// 伪代码 — 蓝图节点名称
ChatbotComponent → Set Vision Component (VisionComponent: EnvironmentWebcamReference)
```

**设置视觉组件** 仅当传入的组件实现了 `true` 时才返回 `UConvaiVisionInterface`.

### 使用多个视觉组件

每个聊天机器人只能有一个活动帧源。当同一个 `IConvaiVisionInterface` 上有多个组件实现了 `Actor`时，聊天机器人会使用发现过程中找到的第一个组件。调用 **设置视觉组件** 以便在 `BeginPlay` 中选择特定来源。

### 启用延迟视觉设置

`AlwaysAllowVision` 是 `UConvaiSettings`上的项目设置。打开 **编辑 > 项目设置 > 插件 > Convai** 并在高级类别中启用 **始终允许视觉** 。

启用后，会话设置将使用连接类型 `video` 即使尚未注册视觉组件也可以。仅当项目在初始连接设置后添加或替换帧源时才使用此选项。对于常规的蓝图设置， **Environment Webcam** 已添加到聊天机器人时， `Actor` 之前调用 `BeginPlay`, **支持视觉** 就足够了。

### 纹理源类型

聊天机器人读取帧时，会在当前活动源上调用 `GetImageTexture` 。 **Environment Webcam** 始终返回 `RenderTarget2D` ，因为它会将画面捕获到 `UTextureRenderTarget2D`.

### 使用网络摄像头图像

当前的 Convai Unreal Engine 插件并未提供可直接读取实体网络摄像头设备的组件。 **Environment Webcam** 会捕获其 `USceneCaptureComponent2D`.

所能看到的内容。对于入门项目，可将网络摄像头图像作为可见场景内容使用：

{% stepper %}
{% step %}

#### 将网络摄像头画面导入 Unreal

使用 Unreal Engine 的媒体工作流，在关卡中显示网络摄像头画面，例如将其显示在平面、网格体或控件上。关键是让网络摄像头图像显示在渲染后的场景中。
{% endstep %}

{% step %}

#### 将 Environment Webcam 对准画面

将 **Environment Webcam** 放置到聊天机器人的 `Actor` 上，并旋转它，使其 `+X` 轴朝向显示网络摄像头画面的表面。
{% endstep %}

{% step %}

#### 将场景捕获到 Convai 渲染目标

指定 **Convai Render Target** 并按照 **开始** 中的说明调用 [视觉快速入门](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-quick-start.md)。由于网络摄像头图像现在已成为捕获场景的一部分，聊天机器人便会接收到该图像的帧。
{% endstep %}

{% step %}

#### 验证捕获的图像

在 Play In Editor 期间打开渲染目标资源。如果预览中显示网络摄像头画面所在的表面，请询问角色该画面中能看到什么。
{% endstep %}
{% endstepper %}

对于无需在关卡中渲染网络摄像头像素、而要直接发送这些像素的生产项目，请实现自定义 C++ 帧源，通过 `IConvaiVisionInterface`提供原始 RGBA 数据。请参阅 [自定义视觉组件](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/custom-vision-components.md).

### 后续步骤

{% 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/ec5b9bfb145ddc8145050976e8e8db28d33fc076" %}
[视觉 Blueprint 参考](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-blueprint-reference.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-frame-sources.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.
