> 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-usage-examples.md).

# 视觉使用示例

应用 Unreal 视觉的常见 Blueprint 模式，包括自动启动捕获、手动控制、FPS 调优和源切换。

这些示例展示了以下实用的 Blueprint 模式： **环境摄像头**。如果尚未为角色添加视觉功能，请先完成 [视觉快速入门](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/vision-quick-start.md) 。

每个示例都包含一个场景、需要应用的设置、预期的运行时行为，以及验证方法。

### 在 BeginPlay 时自动启动视觉功能

**场景：** 固定工作站上的训练 NPC 应在关卡加载后立即开始捕获场景。

**设置：** 在角色 Blueprint 中选择 **环境摄像头** 。在 **详细信息** 面板的 **Convai | Vision**下，启用 `bAutoStartVision`。进入 Play 模式前，指定 **Convai Render Target** 。

**预期行为：** 在 `BeginPlay`期间，组件会调用 **Start**。指定 **Convai Render Target** 后， **Get State** 会返回 `Capturing` ，聊天机器人便可在会话期间发送画面帧。

**验证：** 对聊天机器人调用 **Supports Vision** ，并对 **Environment Webcam** 调用 **环境摄像头**的 `Capturing` 状态。两者都应报告存在活动的视觉源。

### 手动启动和停止

**场景：** 医疗培训模拟应仅在操作阶段使用视觉功能。

**设置：**

1. 在操作开始事件中，获取对 **环境摄像头** 的引用并调用 **启动**.
2. 在流程结束事件中，调用 **停止** 在同一个组件上。
3. 调用 **启动**之前，检查 **获取状态** 以避免事件可能多次触发时重复启动。

**预期行为：** 组件仅在流程处于活动阶段时捕获帧。 **获取状态** 在 `Capturing` 启动后 **启动** 并在 `Stopped` 启动后 **停止后**.

**验证：** 仅在流程处于活动状态时，询问角色有关可见物体的问题。在此阶段之外，回复不应提及场景内容。

### 限制捕获帧率以降低带宽占用

**场景：** 企业入职培训模拟运行在受限网络上，可以接受较低的捕获帧率。

**设置：** 在 **详细信息** 面板中，将 **最大帧率** (`m_MaxFPS`) 设置为 `5`。或者，调用 **设置最大帧率** 并传入数值 `5` ，也可以在 Blueprint 初始化函数中进行设置。

**预期行为：** 聊天机器人读取 `GetMaxFPS()` 并限制帧上传频率，使其大约每 `0.2` 秒上传一帧。

**验证：** 比较更改前后的响应延迟。 **输出日志** 应继续以降低后的频率显示 `SendImage: Sending raw image` 。

### 检查视觉组件是否已注册

**场景：** UI 指示器应显示聊天机器人是否具有有效的帧源。

**设置：** 在事件图表或 Widget 的 Tick 函数中，调用 **支持视觉** 于 `UConvaiChatbotComponent`。使用布尔返回值驱动指示器。

**预期行为：** **支持视觉** 在以下情况下返回 `true` ：聊天机器人上注册了或可发现实现 `UConvaiVisionInterface` 的组件 `Actor`.

**验证：** 同时调用 **获取状态** 于 **环境摄像头**。仅注册还不足以进行上传；源必须处于 `Capturing` 状态。

### 开始捕获后触发逻辑

**场景：** 角色应仅在 **环境摄像头** 进入 `Capturing`.

**设置：** 将 **帧就绪时** 上的事件绑定到 **环境摄像头** 的自定义事件。使用布尔标记确保逻辑只运行一次。

```
// Blueprint 伪代码
bool bSetupComplete = false

OnFrameReady →
  if NOT bSetupComplete:
    bSetupComplete = true
    → trigger setup logic
```

**预期行为：** 组件正在捕获时，首次触发 **帧就绪时** ，设置逻辑会运行一次。

**验证：** 确认自定义逻辑运行前， **获取状态** 返回 `Capturing` 。

### 在运行时切换视觉组件

**场景：** 同一关卡中的两个角色各自拥有自己的 **环境摄像头**。切换到另一个角色时，当前激活的聊天机器人应使用该角色的画面源。

**设置：** 切换事件触发时：

1. 获取目标聊天机器人的 `UConvaiChatbotComponent` 引用。
2. 获取该角色上所需的 **环境摄像头** 组件引用。
3. 调用 **设置视觉组件** 并将摄像头组件传递给聊天机器人。

**预期行为：** **设置视觉组件** 返回 `true` ，并替换之前注册的源。聊天机器人会在下一次上传时钟周期中转发新组件的画面帧。

**验证：** 调用 **支持视觉** 检查目标聊天机器人，并调用新摄像头上的 **获取状态** 。询问一个只有新画面源才能看到的物体。

### 后续步骤

{% 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/dd7a120c7a038befb7a1fe27de94e6b81d28e845" %}
[排查视觉问题](https://docs.convai.com/api-docs/zh/cha-jian-yu-ji-cheng/convai-unreal-engine-plugin/features/vision/troubleshoot-vision.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 %}


---

# 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-usage-examples.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.
