> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs.qualcomm.com/llms.txt
> Use this file to discover all available pages before exploring further.

# 从主机计算机运行

> 在 Windows<sup>®</sup>、Ubuntu 或 macOS<sup>®</sup> 主机计算机上，通过 Dragonwing 评估套件运行多媒体和 AI 示例应用程序。

Qualcomm<sup>®</sup> IoT 平台上的 Ubuntu 提供了多种示例应用程序。每个应用程序都适用于不同的使用场景，例如零售、Qualcomm <sup>®</sup> Edge AI Box 解决方案以及 IP 摄像头。这些示例应用程序可分为以下几类：

* 多媒体示例应用程序，用于展示摄像头、视频和音频功能。
* AI 示例应用程序，用于展示 AI 和机器学习 (ML) 能力。

<h2 id="prerequisites">
  前提条件
</h2>

* 在开始之前，请先完成 [IQ-8275](../devices/iq8275-evk/set-up-the-device) 设备的设置。
* 要启用这些应用程序及所需的 AI 插件，请参阅 [**🔗安装所需软件包**](../devices/iq8275-evk/Install_required_software_packages)。

要使用摄像头，请在目标设备上运行以下命令启用 `camx`：

```shell theme={null}
echo -n "camx" > /var/data
efivar -n 882f8c2b-9646-435f-8de5-f208ff80c1bd-VendorDtbOverlays -w -f /var/data
efivar -n 882f8c2b-9646-435f-8de5-f208ff80c1bd-VendorDtbOverlays -p
sync
reboot
```

## 运行多媒体示例应用程序

多媒体示例应用程序展示了 Dragonwing EVK 上摄像头、显示和视频流的使用场景。

### 多摄像头流传输或编码（行车记录仪）

**说明：** [**gst-multi-camera-example**](https://github.com/qualcomm/gst-plugins-imsdk/tree/main/gst-sample-apps/gst-multi-camera-example) 应用程序允许您同时从两个摄像头传感器进行流传输。该应用程序将摄像头画面并排合成后在屏幕上显示，或对视频流进行编码并保存到文件中。

需要多个摄像头输入的场景包括行车记录仪或立体摄像头。您可以将此应用程序作为参考，并构建自己的用例。例如，一个安防系统，其目标是从多个摄像头捕获视频。您可以查看它，或将其归档以供将来查阅。

下图展示了多个摄像头流的管道。有关此管道中所用元素的更多信息，请参阅[管道流程。](#multi-camera-pipeline-flow)

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/gst_multicamera_example_pipeline.svg" alt="多摄像头管道" />

**图：gst-multi-camera-stream-example 管道**

**应用程序：** [`gst-multi-camera-example`](https://github.com/qualcomm/gst-plugins-imsdk/tree/main/gst-sample-apps/gst-multi-camera-example)

<Accordion title="Try me">
  ### 运行应用程序

  <Note>
    **注意：** 在以下命令中，请提供必要的参数，例如宽度、高度和输出类型。宽度和高度的更改仅适用于主摄像头。
  </Note>

  <Steps>
    <Step title="完成前提条件">
      确保您已完成[前提条件](#prerequisites)。
    </Step>

    <Step title="在目标设备的终端中，选择以下任一用例并运行相应的命令：">
      **Waylandsink 用例：** 查看 Waylandsink 输出：

      ```bash theme={null}
      gst-multi-camera-example -o 0 -w 1920 -h 1080
      ```

      **编码器用例：** 查看编码器输出：

      ```bash theme={null}
      gst-multi-camera-example -o 1 -w 1920 -h 1080
      ```
    </Step>

    <Step title="停止正在运行的用例">
      按 `Ctrl + C`。
    </Step>

    <Step title="在目标设备的终端中，运行以下命令以显示可用的帮助选项：">
      ```bash theme={null}
      gst-multi-camera-example --help
      ```
    </Step>
  </Steps>

  ### 预期输出

  输出会显示在屏幕上并保存到文件中。

  * 如果输出类型为显示，则可以在显示屏上预览视频流。

  * 如果输出类型为视频编码，则编码后的文件将分别保存至
    `/etc/media/cam1_vid.mp4`（摄像头 1）和 `/etc/media/cam2_vid.mp4`（摄像头 2）。

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/multi-camera-example-output.png" alt="摄像头预览输出" />

  **图：gst-multi-camera-example 应用程序的预期输出——预览**

  <h3 id="multi-camera-pipeline-flow">
    管道流程
  </h3>

  下表列出了多摄像头流传输管道中使用的插件：

  <table>
    <thead>
      <tr>
        <th>管道</th>
        <th>说明</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>在显示屏上预览</td>

        <td>
          <ol>
            <li>`qticamsrc` 从 camera0 和 camera1 捕获视频。</li>
            <li>应用 `Capsfilter` 对原始视频数据强制施加约束。</li>
            <li>`qtivcomposer` 合成视频流，并将合成后的视频数据发送到 Wayland 显示接收器。</li>
            <li>`waylandsink` 显示实时预览。</li>
          </ol>
        </td>
      </tr>

      <tr>
        <td>在设备上进行编码器转储</td>

        <td>
          <ol>
            <li>`qticamsrc` 从 camera0 和 camera1 捕获视频。</li>
            <li>应用 `Capsfilter` 对原始视频数据强制施加约束。</li>
            <li>`v4l2h264enc` 用于将视频编码为 H.264 格式。</li>
            <li>`H264parse` 用于解析视频。</li>
            <li>`Mp4mux` 用于将视频多路复用为 MP4 容器。</li>
            <li>`Filesink` 用于将视频写入文件。</li>
          </ol>
        </td>
      </tr>
    </tbody>
  </table>
</Accordion>

### 多通道视频解码与合成（视频墙）

**说明：** [**gst-concurrent-videoplay-composition**](https://github.com/qualcomm/gst-plugins-imsdk/tree/main/gst-sample-apps/gst-concurrent-videoplay-composition) 应用程序支持并发播放 MP4 AVC (H.264) 视频，并在视频墙显示屏上进行合成。

在并发视频播放和合成管道中，四条解码与合成管道并发运行。有关此管道中所用插件的更多信息，请参阅[管道流程。](#video-wall)

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/gst_concurrent_videoplay_composition.svg" alt="单摄像头管道" />

**图：具有四个流的 gst-concurrent-videoplay-composition 管道**

**应用程序：** [`gst-concurrent-videoplay-composition`](https://github.com/qualcomm/gst-plugins-imsdk/tree/main/gst-sample-apps/gst-concurrent-videoplay-composition)

<Accordion title="Try me">
  ### 运行应用程序

  下表列出了通过 gst-concurrent-videoplay-composition 应用程序支持的用例：

  <table>
    <thead>
      <tr>
        <th>用例</th>
        <th>说明</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>视频会议</td>

        <td>
          <ul>
            <li>同时解码多位参与者的视频流。</li>
            <li>适用于多方视频会议场景，应用程序需要管理多路视频流。</li>
          </ul>
        </td>
      </tr>

      <tr>
        <td>监控系统</td>

        <td>
          <ul>
            <li>并发解码来自两个独立摄像头的视频源。</li>
          </ul>
        </td>
      </tr>

      <tr>
        <td>数字标牌</td>

        <td>
          <ul>
            <li>允许对集中管理的信息同时进行更改或更新，并在多个位置以电子方式显示。</li>
          </ul>
        </td>
      </tr>
    </tbody>
  </table>

  要运行这些用例，请执行以下操作：

  <Steps>
    <Step title="完成前提条件">
      确保您已完成[前提条件。](#prerequisites)
    </Step>

    <Step title="准备输入视频文件">
      在目标设备上添加至少一个 `MP4 AVC (H.264)` 视频文件。
    </Step>

    <Step title="运行用例">
      在目标设备的终端中，运行：

      ```bash theme={null}
      gst-concurrent-videoplay-composition -c <number-of-streams> -i <input-file-1>.mp4 -i <input-file-2>.mp4
      ```

      **命令行参数**

      | 参数   | 说明                                |
      | ---- | --------------------------------- |
      | `-c` | 用于合成的解码流数量。支持的值：`2`、`4`、`8`、`16`。 |
      | `-i` | 输入视频文件的绝对路径。                      |

      **示例**

      * **并发播放两个会话**

        ```bash theme={null}

        gst-concurrent-videoplay-composition -c 2 -i /etc/media/video_avc.mp4 -i /etc/media/video_avc.mp4
        ```
      * **并发播放四个会话**
        ```bash theme={null}

        gst-concurrent-videoplay-composition -c 4 -i /etc/media/video_avc.mp4 -i /etc/media/video_avc.mp4 -i /etc/media/video_avc.mp4 -i /etc/media/video_avc.mp4
        ```
    </Step>

    <Step title="停止正在运行的用例">
      按 `Ctrl + C`。
    </Step>

    <Step title="在目标设备的终端中，运行以下命令以显示可用的帮助选项：">
      ```bash theme={null}
      gst-concurrent-videoplay-composition --help
      ```
    </Step>
  </Steps>

  ### 预期输出

  各个合成流被拼接在一起，作为统一的视频流显示。

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/video-wall-output.png" alt="视频墙输出" />

  **图：gst-concurrent-videoplay-composition 应用程序的预期输出**

  <h3 id="video-wall">
    管道流程
  </h3>

  下表列出了运行视频墙管道所使用的插件：

  <table>
    <thead>
      <tr>
        <th>插件</th>
        <th>说明</th>
      </tr>
    </thead>

    <tbody>
      <tr>
        <td>filesrc</td>

        <td>
          <ol>
            读取视频数据。
          </ol>
        </td>
      </tr>

      <tr>
        <td>qtdemux</td>

        <td>
          <ol>
            对视频数据进行解多路复用。
          </ol>
        </td>
      </tr>

      <tr>
        <td>h264parse</td>

        <td>
          <ol>
            解析 H.264 视频流。
          </ol>
        </td>
      </tr>

      <tr>
        <td>v4l2h264dec</td>

        <td>
          <ol>
            解码 H.264 视频流。
          </ol>
        </td>
      </tr>

      <tr>
        <td>qtivcomposer</td>

        <td>
          <ol>
            合成已解码的视频流，并通过显示屏输出。
          </ol>
        </td>
      </tr>

      <tr>
        <td>waylandsink</td>

        <td>
          <ol>
            在 Wayland 显示屏上显示合成后的视频流。
          </ol>
        </td>
      </tr>
    </tbody>
  </table>
</Accordion>

## 运行 AI 示例应用程序

AI 示例应用程序展示了在 Dragonwing EVK 上，对来自摄像头、视频文件或实时流传输协议 (RTSP) 流的输入进行对象检测、多路推理以及并行推理的使用场景。

<h3 id="download-ai-models">
  下载并传输 AI 模型和标签
</h3>

要运行 AI 示例应用程序，请使用以下任一方法下载所需的模型和标签：

* 从 [Qualcomm® AI Hub](https://aihub.qualcomm.com/iot/models) 下载 AI 模型，并从 GitHub 下载标签
* 使用 `download_artifacts.sh` 脚本下载 AI 模型和标签

  在目标设备上，获取 `download_artifacts.sh` 脚本，设置可执行权限，并运行它以下载模型、媒体和标签文件：

  ```bash theme={null}
  cd /tmp/
  curl -L -O https://raw.githubusercontent.com/qualcomm/sample-apps-for-qualcomm-linux/refs/heads/main/qualcomm-linux/scripts/download_artifacts_2.x.sh
  sudo chmod +x download_artifacts.sh 
  sudo ./download_artifacts.sh
  ```

要运行对象检测、并行推理和多路推理 AI 用例，应用程序会使用以下 AI 模型：

| 示例应用程序   | 所需模型                                                                                                                                                                                                                                                                                                                               |
| -------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| AI 对象检测  | [yolox\_quantized.tflite](https://aihub.qualcomm.com/iot/models/yolox?searchTerm=yolo*)                                                                                                                                                                                                                                            |
| 并行 AI 推理 | [yolox\_quantized.tflite](https://aihub.qualcomm.com/iot/models/yolox?searchTerm=yolo*)<br />[Inception-v3](https://aihub.qualcomm.com/iot/models/inception_v3)<br />[HRNetPose](https://aihub.qualcomm.com/iot/models/hrnet_pose)<br />[DeepLabV3-Plus-MobileNet](https://aihub.qualcomm.com/iot/models/deeplabv3_plus_mobilenet) |
| 多路推理     | [yolox\_quantized.tflite](https://aihub.qualcomm.com/iot/models/yolox?searchTerm=yolo*)<br />[Inception-v3](https://aihub.qualcomm.com/iot/models/inception_v3)                                                                                                                                                                    |

### AI 对象检测

**说明：** [**gst-ai-object-detection**](https://github.com/qualcomm/gst-plugins-imsdk/blob/main/gst-sample-apps/gst-ai-object-detection/main.c) 应用程序允许您在图像和视频中检测对象。这些用例展示了在 Qualcomm AI 硬件加速器上运行 [**YOLOv5**](https://github.com/ultralytics/yolov5)、[**YOLOv8**](https://github.com/ultralytics/ultralytics) 和 [**YOLOX**](https://github.com/Megvii-BaseDetection/YOLOX/blob/main/README.md)。

下图展示了管道，它从实时摄像头画面、文件、USB 源或 RTSP 流接收输入，进行预处理，然后在 AI 硬件上运行推理。结果既可以显示在屏幕上，也可以保存为编码的 MP4 文件，或通过 RTSP 服务器进行流传输。有关管道流程中使用的插件信息，请参阅[**管道流程**](#object-detection-pipeline-flow)

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/ai-sample-applications-object-detection-pipeline-flow.png" alt="管道图" caption="管道图" />

**应用程序：** [`gst-ai-object-detection`](https://github.com/qualcomm/gst-plugins-imsdk/blob/main/gst-sample-apps/gst-ai-object-detection/main.c)

<Accordion title="Try me">
  #### 输入和输出能力

  | 文件源 | RTSP | USB 摄像头 | MIPI 摄像头 | IMX577 摄像头 | 文件输出 | 显示 | RTSP 输出 |
  | --- | ---- | ------- | -------- | ---------- | ---- | -- | ------- |
  | 是   | 是    | 是       | 否        | 是          | 是    | 是  | 是       |
  | 是   | 是    | 是       | 是        | 是          | 是    | 是  | 是       |

  #### 示例模型和标签文件

  | 运行时                            | 模型文件                                                     | 标签文件           |
  | ------------------------------ | -------------------------------------------------------- | -------------- |
  | Qualcomm Neural Processing SDK | `yolonas.dlc`                                            | `yolonas.json` |
  | LiteRT                         | `yolov8_det_quantized.tflite` / `yolox_quantized.tflite` | `yolox.json`   |
  | Qualcomm AI Engine Direct      | `yolov8_det_quantized.bin`                               | `yolov8.json`  |

  #### 在目标设备上运行应用程序

  <Steps>
    <Step title="下载构件">
      确保您已将所有所需的构件[下载](#download-ai-models)到目标设备。
    </Step>

    <Step title="运行应用程序">
      ```bash theme={null}
      gst-ai-object-detection --config-file=/etc/configs/config_detection.json
      ```

      示例应用程序使用 `/etc/configs/config_detection.json` 文件读取输入参数。

      要显示所有可用选项：

      ```bash theme={null}
      gst-ai-object-detection -h
      ```

      要停止用例，请按 **CTRL + C**。
    </Step>
  </Steps>

  #### 配置

  gst-ai-object-detection 应用程序使用 `/etc/configs/config_detection.json` 文件。更新其属性以匹配您的模型、输入流和输出。有关所有字段，请参阅[**Config JSON 字段说明**](#object-detection-config-json-description)。

  ```json theme={null}
  {
    "file-path": "<path-to-input-video>",
    "ml-framework": "<snpe or tflite or qnn framework>",
    "yolo-model-type": "<yolov8 or yolonas or yolov5 or yolox>",
    "model": "<path-to-model-file>",
    "labels": "<path-to-label-file>",
    "threshold": <post processsing threshold, integer value from 1 to 100>,
    "runtime": "<dsp, gpu, cpu runtime>",
    "output-type": "waylandsink or filesink or rtspsink",
    "snpe-tensors": "<model output tensor name>"
  }
  ```

  <Note>
    对于 USB 摄像头输入，请在配置文件中设置 `video-format`、`resolution` 和 `framerate` 参数，
    以匹配摄像头的能力，请参阅[配置 USB 摄像头](https://dragonwingdocs.qualcomm.com/System/Interfaces/usb#configure-usb-camera)。
  </Note>

  <Note>
    `snpe-tensors` 字段仅适用于 SNPE 运行时。要获取 DLC 模型的输出张量名称，请在 [**Netron**](https://netron.app/) 中打开该模型。
  </Note>

  <Note>
    使用来自 AI Hub 的 DLC 模型时，`snpe-tensors` 字段是可选的。
  </Note>

  <Accordion title="可用配置">
    摄像头源、LiteRT 模型、DSP 运行时

    ```json theme={null}
    {
      "camera": 0,
      "ml-framework": "tflite",
      "yolo-model-type": "yolox",
      "model": "/etc/models/yolox_quantized.tflite",
      "labels": "/etc/labels/yolox.json",
      "threshold": 40,
      "runtime": "dsp",
      "output-type": "waylandsink",
      "snpe-tensors": "<Model output tensor name>"
    }
    ```
  </Accordion>

  #### 预期输出

  检测到的对象及其边界框和标签会叠加在视频上，并显示在本地显示屏上。

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/gst-ai-object-detection.png" alt="输出图" />

  <h4 id="object-detection-pipeline-flow">
    管道流程
  </h4>

  下表列出了对象检测管道中使用的插件：

  | 插件                                                                                                                                                                       | 说明                                                                                                                                                               |
  | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | [`qticamsrc`](https://imsdkdocs.qualcomm.com/plugin-reference/qticamsrc)                                                                                                 | • 从摄像头捕获实时流。<br /> • 使用 `tee` 拆分视频流以进行推理。                                                                                                                        |
  | `filesrc`                                                                                                                                                                | • 使用 `filesrc` 捕获视频流，随后由 `qtdemux` 对视频流进行解多路复用。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                      |
  | `rtspsrc`                                                                                                                                                                | • 使用 `rtspsrc` 捕获 RTSP 流，随后由 `rtph264depay` 提取视频。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                    |
  | `v4l2src`                                                                                                                                                                | • 从 USB 摄像头捕获实时流。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                                                    |
  | `h264parse`                                                                                                                                                              | 解析 H.264 视频比特流。                                                                                                                                                  |
  | [`v4l2h264dec`](https://imsdkdocs.qualcomm.com/plugin-reference/v4l2h264dec)                                                                                             | 通过硬件将 H.264 视频解码为原始帧。                                                                                                                                            |
  | [`qtimlvconverter`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlvconverter)                                                                                     | 1. 在其接收器 pad 上接收视频流。<br />2. 对流数据执行以下预处理：<br />   • 颜色转换<br />   • 缩放（放大或缩小）<br />   • 归一化<br />3. 将预处理后的视频流转换为张量流。<br />该张量流将在管道的后续阶段用于推理。                      |
  | [`qtimlsnpe`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlsnpe)<br />[`qtimltflite`](plugin-reference/qtimltflite)<br />[`qtimlqnn`](plugin-reference/qtimlqnn) | 1. 推理运行时在其接收器 pad 上接收张量流后，使用提供的模型运行推理。<br />2. 在其源 pad 上产生带有推理结果的张量流。                                                                                            |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess)                                                                                   | 处理来自任何对象检测模型的推理结果。<br />1. 对所选数量的结果应用阈值。<br />2. 加载 YOLO（YOLOv5、YOLOv8 或 YOLO-NAS）模块。<br />3. 生成仅包含可叠加在对象上的边界框的视频帧。<br />4. 将这些处理后的帧发送到 `qtivcomposer` 的接收器 pad。 |
  | [`qtivcomposer`](https://imsdkdocs.qualcomm.com/plugin-reference/qtivcomposer)                                                                                           | 1. 使用其接收器 pad 上的内容合成帧。<br />2. 将包含这些合成帧的 GStreamer 缓冲区推送到其源 pad。                                                                                                 |
  | [`waylandsink`](https://imsdkdocs.qualcomm.com/plugin-reference/waylandsink)                                                                                             | 1. 将其接收器 pad 上接收到的视频流提交给 Weston。<br />2. Weston 在本地显示屏上渲染视频流。                                                                                                    |
  | `filesink`                                                                                                                                                               | 在接收器 pad 上接收视频流，并将其保存为 H.264 编码的 MP4 文件。                                                                                                                         |
  | [`qtirtspbin`](https://imsdkdocs.qualcomm.com/plugin-reference/qtirtspbin)                                                                                               | 1. 作为网络接收器。<br />2. 向网络传输 UDP 数据包。                                                                                                                               |

  <h4 id="object-detection-config-json-description">
    Config JSON 字段说明
  </h4>

  | 字段                                       | 值 / 说明                                                                                                                                                                                           |   |
  | :--------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | - |
  | `ml-framework`                           | 支持的 ML 框架：<br />• `snpe`（Qualcomm Neural Processing SDK）<br />• `tflite`（LiteRT）<br />• `qnn`（Qualcomm AI Engine Direct）                                                                         |   |
  | `yolo-model-type`                        | 支持的 YOLO 架构：<br />• `yolov8`<br />• `yolonas`<br />• `yolov5`<br />• `yolox`                                                                                                                     |   |
  | `runtime`                                | 硬件运行时：<br />• `cpu`<br />• `gpu`<br />• `dsp`                                                                                                                                                    |   |
  | `Input source`                           | 支持的输入源：<br />• `camera`（0=主摄像头，1=辅摄像头）<br />• `file-path`<br />• `rtsp-ip-port`<br />• `usb-camera`（将 `enable-usb-camera` 设置为 `TRUE`）                                                            |   |
  | `output-ip-address`                      | 输出 RTSP 服务器 IP 地址                                                                                                                                                                                |   |
  | `port`                                   | 输出 RTSP 服务器端口                                                                                                                                                                                    |   |
  | `output-type`                            | 支持的输出接收器：<br />• `waylandsink`（显示）<br />• `filesink`（MP4 文件）<br />• `rtspsink`（RTSP 流）                                                                                                           |   |
  | `snpe-tensors`                           | `["output-tensor-name", "output-tensor-name"]`                                                                                                                                                   |   |
  | `USB camera video-format and resolution` | 1. 使用以下 `video-format` 选项之一：<br />   • `waylandsink`（显示）<br />   • `filesink`（MP4 文件）<br />   • `rtspsink`（RTSP 流）<br />2. 使用以下分辨率字段：<br />   • `width`<br />   • `height`<br />   • `framerate` |   |
  | `output-file`                            | 输出文件名。默认输出文件为 `output_object_detection.mp4`。                                                                                                                                                     |   |
</Accordion>

### 并行 AI 推理

**说明**：[**gst-ai-parallel-inference**](https://github.com/qualcomm/gst-plugins-imsdk/blob/main/gst-sample-apps/gst-ai-parallel-inference/main.c) 应用程序允许您对来自不同源（例如摄像头、文件或 RTSP 网络）的输入流执行对象检测、对象分类、姿势检测和图像分割。这些用例分别为对象检测、图像分割、分类和姿势检测实现了 LiteRT 模型。

下图展示了管道，它从摄像头、文件或 RTSP 流接收输入流，为这四个用例执行并行推理，并将结果并排显示在屏幕上。

有关此管道中所用插件的信息，请参阅[**管道流程**](#parallel-inference-pipeline-flow)。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/gst_ai_parallel_inference_pipeline.svg" alt="管道图" caption="管道图" />

**应用程序：** [`gst-ai-parallel-inference`](https://github.com/qualcomm/gst-plugins-imsdk/blob/main/gst-sample-apps/gst-ai-parallel-inference/main.c)

<Accordion title="Try me">
  #### 输入和输出能力

  | 文件源 | RTSP | USB 摄像头 | MIPI 摄像头 | 文件输出 | 显示 | RTSP 输出 |
  | --- | ---- | ------- | -------- | ---- | -- | ------- |
  | 是   | 是    | 否       | 是        | 否    | 是  | 否       |

  #### 示例模型和标签文件

  | 运行时    | 模型文件                                                                                                                                                                                         | 标签文件                                                                                                                                                           |
  | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | LiteRT | detection：`yolox_quantized.tflite`<br />classification：`inception_v3_quantized.tflite`<br />segmentation：`deeplabv3_plus_mobilenet_quantized.tflite`<br />pose：`hrnet_pose_quantized.tflite` | detection：`yolox.json`<br />classification：`classification.json`<br />segmentation：`deeplabv3_resnet50.json`<br />pose：`hrnet_pose.json`、`hrnet_settings.json` |

  #### 在目标设备上运行应用程序

  <Steps>
    <Step title="下载构件">
      确保您已将所有所需的构件[下载](#download-ai-models)到目标设备。
    </Step>

    <Step title="运行应用程序">
      ```bash theme={null}
      gst-ai-parallel-inference --config-file=/etc/configs/config-parallel-inference.json
      ```

      示例应用程序使用 `/etc/configs/config-parallel-inference.json` 文件读取输入参数。

      要显示所有可用选项：

      ```bash theme={null}
      gst-ai-parallel-inference -h
      ```

      要停止用例，请按 **CTRL + C**。
    </Step>
  </Steps>

  #### 配置

  gst-ai-parallel-inference 应用程序使用 `/etc/configs/config-parallel-inference.json` 文件。更新其属性以匹配您的模型、输入流和输出。有关所有字段，请参阅[**Config JSON 字段说明**](#parallel-inference-config-json-description)。

  ```json theme={null}
  {
    "camera": "<camera-id>",
    "file-path": "<input-video-path>",
    "rtsp-ip-port": "<RTSP-IP-Port-address>",
    "detection-model": "<path-to-detection model>",
    "detection-labels": "<path-to-detection-labels>",
    "pose-model": "<path-to-pose-model>",
    "pose-labels": "<path-to-pose-label>",
    "pose-settings-path": "<path-to-pose-settings-file>",
    "segmentation-model": "<path-to-segmentation-model>",
    "segmentation-labels": "<path-to-segmentation-labels>",
    "classification-model": "<path-to-classification-model>",
    "classification-labels": "<path-to-classification-labels>"
  }
  ```

  <Note>
    对于 QCS6490，如果配置文件中不存在 `file-path` 和 `rtsp-ip-port`，则将选择摄像头输入。
  </Note>

  <Accordion title="可用配置">
    文件源、LiteRT 模型、DSP 运行时

    ```json theme={null}
    {
        "file-path": "/etc/media/video.mp4",
        "detection-model": "/etc/models/yolox_quantized.tflite",
        "detection-labels": "/etc/labels/yolox.json",
        "pose-model": "/etc/models/hrnet_pose_quantized.tflite",
        "pose-labels": "/etc/labels/hrnet_pose.json",
        "pose-settings-path": "/etc/labels/hrnet_settings.json",
        "segmentation-model": "/etc/models/deeplabv3_plus_mobilenet_quantized.tflite",
        "segmentation-labels": "/etc/labels/deeplabv3_resnet50.json",
        "classification-model": "/etc/models/inception_v3_quantized.tflite",
        "classification-labels": "/etc/labels/classification.json"
    }
    ```
  </Accordion>

  #### 预期输出

  在执行四路并行推理后，结果将并排显示在屏幕上。

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/expected_output_gst-ai-parallel-inference.png" alt="管道图" caption="管道图" />

  <h4 id="parallel-inference-pipeline-flow">
    管道流程
  </h4>

  下表列出了元数据解析器管道中使用的插件：

  | 插件                                                                                          | 说明                                                                                                                                                                                                                                       |
  | ------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | [`qticamsrc`](https://imsdkdocs.qualcomm.com/plugin-reference/qticamsrc)                    | • 从摄像头捕获实时流。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                                                                                                                                 |
  | `filesrc`                                                                                   | • 使用 `filesrc` 捕获视频流。<br />• 随后由 `qtdemux` 对视频流进行解多路复用。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                                                                                      |
  | `rtspsrc`                                                                                   | • 使用 `rtspsrc` 捕获 RTSP 流。<br />• 随后由 `rtph264depay` 提取视频。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                                                                                    |
  | `h264parse`                                                                                 | 解析 H.264 视频。                                                                                                                                                                                                                             |
  | [`v4l2h264dec`](https://imsdkdocs.qualcomm.com/plugin-reference/v4l2h264dec)                | 解码视频。                                                                                                                                                                                                                                    |
  | [`qtimlvconverter`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlvconverter)        | 1. 在其接收器 pad 上接收视频流。<br />2. 当模型预期使用浮点值作为输入时，对流数据执行以下预处理：<br />  • 颜色转换<br />  • 缩放（放大或缩小）<br />  • 归一化<br />3. 该张量流将在管道的后续阶段用于推理。                                                                                                       |
  | [`qtimltflite`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimltflite)                | • 推理运行时在其接收器 pad 上接收到张量流后，运行推理。<br />• 在其源 pad 上产生带有推理结果的张量流。                                                                                                                                                                            |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 检测 | a. 接收来自对象检测模型的推理张量。<br />b. 将其接收器 pad 上的推理张量转换为多媒体插件后续可处理的视频或文本等格式。<br />c. 对所选数量的结果应用阈值。<br />d. 加载检测模型对应的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载 YOLOv8 子模块。<br />  • 生成文本结构的结果。<br />  • 将其发送到 `qtimetamux` 的接收器 pad。   |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 分类 | a. 接收来自分类模型的推理张量。<br />b. 将其接收器 pad 上的推理张量转换为多媒体插件后续可处理的视频或文本等格式。<br />c. 对所选数量的结果应用阈值。<br />d. 加载分类模型对应的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载模型的子模块。<br />  • 生成带有分类标签的视频帧作为结果。<br />  • 将其发送到 `qtivcomposer` 的接收器 pad。 |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 分割 | a. 在其接收器 pad 上接收推理张量。<br />b. 将推理张量转换为多媒体插件后续可处理的视频格式。<br />c. 生成帧的语义分割结果。<br />d. 加载分割模型对应的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载 deeplab-argmax 子模块。<br />  • 生成带有分割掩码的视频帧。<br />  • 将其发送到 `qtivcomposer` 的接收器 pad。     |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 姿势 | a. 在其接收器 pad 上接收推理张量。<br />b. 将推理张量转换为多媒体插件后续可处理的视频格式。<br />c. 对所选数量的结果应用阈值。<br />d. 加载各种姿势估计模型对应的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载 HRNet 模块。<br />  • 生成带有姿势绘制的视频帧作为结果。<br />  • 将其发送到 `qtivcomposer` 的接收器 pad。     |
  | [`qtivcomposer`](https://imsdkdocs.qualcomm.com/plugin-reference/qtivcomposer)              | 1. 使用其接收器 pad 上的内容合成帧。<br />2. 将包含这些合成帧的 GStreamer 缓冲区推送到其源 pad。                                                                                                                                                                         |
  | [`waylandsink`](https://imsdkdocs.qualcomm.com/plugin-reference/waylandsink)                | 1. 将其接收器 pad 上接收到的视频流提交给 Weston。<br />2. Weston 在本地显示屏上渲染视频流。                                                                                                                                                                            |

  <h4 id="parallel-inference-config-json-description">
    Config JSON 字段说明
  </h4>

  | 字段                  | 值/说明                                                                                                                                                                                                                                                                                 |
  | ------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
  | `Input source`      | 使用以下输入源之一：<br />• `camera`：主摄像头 (`0`) 或辅摄像头 (`1`)。<br />• `file-path`：视频文件的目录路径。<br />• `rtsp-ip-port`：RTSP 流的地址：`rtsp://<ip>:<port>/<stream>`                                                                                                                                       |
  | `Models and labels` | • `detection-model`：检测模型的路径。<br />• `detection-labels`：检测标签的路径。<br />• `pose-model`：姿势模型的路径。<br />• `pose-labels`：姿势标签的路径。<br />• `segmentation-model`：分割模型的路径。<br />• `segmentation-labels`：分割标签的路径。<br />• `classification-model`：分类模型的路径。<br />• `classification-labels`：分类标签的路径。 |
</Accordion>

### 多路推理

**说明**：[**gst-ai-multistream-inference**](https://github.com/qualcomm/gst-plugins-imsdk/blob/main/gst-sample-apps/gst-ai-multistream-inference/main.c) 应用程序展示了对来自摄像头、文件或 RTSP 流的最多 32 路输入流进行 AI 推理（对象检测和分类）。

下图展示了管道，它接收多路输入流，对它们进行预处理，运行 AI 推理，合成这些流，并将它们合并为单一视频输出。

在 1080P 和 720P 上验证的每种 SoC 支持的最大输入流数量如下：

* QCS6490 – 8

* Dragonwing IQ-8275 – 16

* Dragonwing IQ-9075 – 32

  输出可以显示在 HDMI 显示屏上，保存为 H.264 编码的 MP4
  文件，或转换为 RTSP 流。

有关此管道中所用插件的信息，请参阅[**管道流程**](#multistream-inference-pipeline-flow)。

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/gst_ai_multistream_inference_pipeline.svg" alt="管道图" caption="管道图" />

**应用程序：** [`gst-ai-multistream-inference`](https://github.com/qualcomm/gst-plugins-imsdk/blob/main/gst-sample-apps/gst-ai-multistream-inference/main.c)

<Accordion title="Try me">
  #### 输入和输出能力

  | 文件源 | RTSP | USB 摄像头 | MIPI 摄像头 | 文件输出 | 显示 | RTSP 输出 |
  | --- | ---- | ------- | -------- | ---- | -- | ------- |
  | 是   | 是    | 否       | 是        | 是    | 是  | 是       |

  #### 示例模型和标签文件

  | 运行时    | 模型文件                                                                                   | 标签文件                                                             |
  | ------ | -------------------------------------------------------------------------------------- | ---------------------------------------------------------------- |
  | LiteRT | detection：`yolox_quantized.tflite`<br />classification：`inception_v3_quantized.tflite` | detection：`yolox.json`<br />classification：`classification.json` |

  #### 在目标设备上运行应用程序

  <Steps>
    <Step title="下载构件">
      确保您已完成[`前提条件`](#prerequisites)。这将下载所有所需的构件到目标设备。
    </Step>

    <Step title="运行应用程序">
      ```bash theme={null}
      gst-ai-multistream-inference --config-file=/etc/configs/config-multistream-inference.json
      ```

      示例应用程序使用 `/etc/configs/config-multistream-inference.json` 文件读取输入参数。

      要显示所有可用选项：

      ```bash theme={null}
      gst-ai-multistream-inference -h
      ```

      要停止用例，请按 **CTRL + C**。
    </Step>
  </Steps>

  #### 配置

  gst-ai-multistream-inference 应用程序使用 `/etc/configs/config-multistream-inference.json` 文件。更新其属性以匹配您的模型、输入流和输出。有关所有字段，请参阅[**Config JSON 字段说明**](#multistream-inference-config-json-description)。

  ```json theme={null}
  {
    "input-file-path": ["<input file 1>", "<input file 2>"],
    "input-rtsp-path": ["<rtsp stream 1>", "<rtsp stream 2 >"],
    "input-type": "<h264 or h265>",
    "model": "<path to model file>",
    "labels": "<path to label file>",
    "output-display": "<0 or 1>",
    "output-file-path": "<output file path>",
    "output-ip-address": "<ip address of test kit>",
    "output-port-number": "<port number over which rtsp stream can be listened>",
    "use-case": "<0 or 1>"
  }
  ```

  <Note>
    如果观察到性能下降，您可以使用 YOLOv8 LiteRT 模型。有关 YOLOv8 导出说明，请参阅[**前提条件**](#prerequisites)。
  </Note>

  <Accordion title="可用配置">
    对 8 路 H.264 文件输入进行对象检测、LiteRT 模型、DSP 运行时

    ```json theme={null}
    {
      "input-file-path":
        [
          "/etc/media/video.mp4",
          "/etc/media/video.mp4",
          "/etc/media/video.mp4",
          "/etc/media/video.mp4",
          "/etc/media/video.mp4",
          "/etc/media/video.mp4",
          "/etc/media/video.mp4",
          "/etc/media/video.mp4"
        ],
      "model": "/etc/models/yolox_quantized.tflite",
      "labels": "/etc/labels/yolox.json",
      "input-type": "h264",
      "output-display": 1,
      "use-case": 0
    }
    ```
  </Accordion>

  #### 预期输出

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/Ubuntu/images/run-sample-applications/multistream.png" alt="管道图" caption="管道图" />

  <h4 id="multistream-inference-pipeline-flow">
    管道流程
  </h4>

  下表列出了元数据解析器管道中使用的插件：

  | 插件                                                                                     | 说明                                                                                                                                                                                                                                                                                                           |
  | :------------------------------------------------------------------------------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | [`qticamsrc`](https://imsdkdocs.qualcomm.com/plugin-reference/qticamsrc)               | • 从摄像头捕获实时流。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                                                                                                                                                                                                     |
  | `filesrc`                                                                              | • 使用 `filesrc` 捕获视频流，随后由 `qtdemux` 对视频流进行解多路复用。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                                                                                                                                                                  |
  | `rtspsrc`                                                                              | • 使用 `rtspsrc` 捕获 RTSP 流，随后由 `rtph264depay` 提取视频。<br />• 使用 `tee` 拆分视频流以进行推理。                                                                                                                                                                                                                                |
  | `h264parse`                                                                            | • 解析 H.264 视频。                                                                                                                                                                                                                                                                                               |
  | [`v4l2h264dec`](https://imsdkdocs.qualcomm.com/plugin-reference/v4l2h264dec)           | • 解码视频。                                                                                                                                                                                                                                                                                                      |
  | [`qtimlvconverter`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlvconverter)   | 1. 在其接收器 pad 上接收视频流。<br />2. 当模型预期使用浮点值作为输入时，对流数据执行以下预处理：<br />   • 颜色转换<br />   • 缩放（放大或缩小）<br />   • 归一化<br />3. 在其源 pad 上将预处理后的视频流转换为张量流。<br />该张量流将在管道的后续阶段用于推理。                                                                                                                                         |
  | [`qtimltflite`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimltflite)           | 1. 推理运行时在其接收器 pad 上接收到张量流后，运行推理。<br />2. 在其源 pad 上产生带有推理结果的张量流。                                                                                                                                                                                                                                              |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) | 处理来自任何对象检测、分类、姿势检测和分割模型的推理结果。<br /><br />**检测用例：**<br />   • 对所选数量的结果应用阈值。<br />   • 加载 YOLOv8 模块。<br />   • 生成仅包含可叠加在对象上的边界框的视频帧，并将其发送到 `qtivcomposer` 的接收器 pad。<br /><br />**分类用例：**<br />   • 对所选数量的结果应用阈值。<br />   • 加载 MobileNet-softmax 模块。<br />   • 生成带有分类标签的视频帧作为结果，并将其发送到 `qtivcomposer` 的接收器 pad。 |
  | [`qtivcomposer`](https://imsdkdocs.qualcomm.com/plugin-reference/qtivcomposer)         | 1. 使用其接收器 pad 上的内容合成帧。<br />2. 将包含这些合成帧的 GStreamer 缓冲区推送到其源 pad。                                                                                                                                                                                                                                             |
  | [`waylandsink`](https://imsdkdocs.qualcomm.com/plugin-reference/waylandsink)           | 1. `waylandsink` 将其接收器 pad 上接收到的视频流提交给 Weston。<br />2. Weston 在本地显示屏上渲染视频流。                                                                                                                                                                                                                                  |
  | `filesink`                                                                             | 1. 在其接收器 pad 上接收视频流。<br />2. 将该视频流保存为 H.264 编码的 MP4 文件。                                                                                                                                                                                                                                                      |
  | [`qtirtspbin`](https://imsdkdocs.qualcomm.com/plugin-reference/qtirtspbin)             | 1. 作为网络接收器。<br />2. 向网络传输 UDP 数据包。                                                                                                                                                                                                                                                                           |

  <h4 id="multistream-inference-config-json-description">
    Config JSON 字段说明
  </h4>

  | 字段             | 值 / 说明                                                                                                                                                                                                           |
  | :------------- | :--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | `Input source` | 使用以下输入源之一：<br />   • `num-camera`：来自摄像头的输入数量。<br />   • `camera`：当 `num-camera=1` 时的输入摄像头。<br />   • `input-file-path`：视频文件的目录路径。<br />   • `input-rtsp-path`：RTSP 流的地址：`rtsp://<ip>:<port>/<stream>`            |
  | `input-type`   | 文件和 RTSP 输入的视频编码类型：<br />   • `H.264`<br />   • `H.265`                                                                                                                                                          |
  | `Output`       | 使用以下输出之一：<br />   • `output-file-path`：保存输出文件的目录路径。<br />   • `output-ip-address`：可播放 RTSP 流的设备的 IP 地址。<br />   • `output-port-number`：可播放 RTSP 流的设备的端口号。<br />   • `output-display`：用于预览的已连接显示设备。选择 `1` 以启用此选项。 |
</Accordion>

## 参考文档

要进一步探索示例应用程序，

* 请参阅[IMSDK AI 示例应用程序](https://imsdkdocs.qualcomm.com/sample-application/ai-sample-applications)了解基于 AI 的示例应用程序。
* 请参阅[IMSDK MM 示例应用程序](https://imsdkdocs.qualcomm.com/sample-application/multimedia-sample-applications)了解基于 MM 的示例应用程序。
