> ## 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-9075](../devices/iq9075-evk/set-up-the-device) 设备。
* 要启用这些应用程序和必要的 AI 插件，请参阅 [**🔗安装所需软件包**](../devices/iq9075-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` 和 `/etc/media/cam2_vid.mp4` 中，对应摄像头 1 和摄像头 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) 应用程序允许您检测图像和视频中的对象。这些用例展示了 [**YOLOv5**](https://github.com/ultralytics/yolov5)、[**YOLOv8**](https://github.com/ultralytics/ultralytics) 和 [**YOLOX**](https://github.com/Megvii-BaseDetection/YOLOX/blob/main/README.md) 在 Qualcomm AI 硬件加速器上的执行情况。

下图显示了管道，它从实时摄像头源、文件、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` 文件。请更新其属性以匹配您的模型、输入流和输出。有关所有字段，请参阅[**配置 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. 在其接收端接收视频流。<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. 推理运行时在其接收端接收张量流后，使用提供的模型运行推理。<br />2. 在其源端产生包含推理结果的张量流。                                                                                                        |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess)                                                                                   | 处理来自任何对象检测模型的推理结果。<br />1. 对所选数量的结果应用阈值。<br />2. 加载 YOLO（YOLOv5、YOLOv8 或 YOLO-NAS）模块。<br />3. 产生仅带有边界框的视频帧，这些边界框可叠加在对象上。<br />4. 将这些处理后的帧发送到 `qtivcomposer` 的接收端。 |
  | [`qtivcomposer`](https://imsdkdocs.qualcomm.com/plugin-reference/qtivcomposer)                                                                                           | 1. 使用来自其接收端的内容合成帧。<br />2. 将包含这些合成帧的 GStreamer 缓冲区推送到其源端。                                                                                                         |
  | [`waylandsink`](https://imsdkdocs.qualcomm.com/plugin-reference/waylandsink)                                                                                             | 1. 将其接收端接收到的视频流提交给 Weston。<br />2. Weston 将视频流渲染到本地显示器上。                                                                                                          |
  | `filesink`                                                                                                                                                               | 在接收端接收视频流，并将其保存为 H.264 编码的 MP4 文件。                                                                                                                                |
  | [`qtirtspbin`](https://imsdkdocs.qualcomm.com/plugin-reference/qtirtspbin)                                                                                               | 1. 作为网络接收器。<br />2. 向网络传输 UDP 数据包。                                                                                                                                |

  <h4 id="object-detection-config-json-description">
    配置 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` 文件。请更新其属性以匹配您的模型、输入流和输出。有关所有字段，请参阅[**配置 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. 在其接收端接收视频流。<br />2. 当模型期望浮点值作为输入时，对流数据执行以下预处理：<br />  • 颜色转换<br />  • 缩放（放大或缩小）<br />  • 归一化<br />3. 该张量流将在管道的后续阶段用于推理。                                                                                                        |
  | [`qtimltflite`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimltflite)                | • 推理运行时在其接收端接收张量流后，运行推理。<br />• 在其源端产生包含推理结果的张量流。                                                                                                                                                                                 |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 检测 | a. 从对象检测模型接收推理张量。<br />b. 将接收端上的推理张量转换为多媒体插件后续可处理的格式，例如视频或文本。<br />c. 对所选数量的结果应用阈值。<br />d. 加载对应检测模型的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载 YOLOv8 子模块。<br />  • 以文本结构形式生成结果。<br />  • 将它们发送到 `qtimetamux` 的接收端。   |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 分类 | a. 从分类模型接收推理张量。<br />b. 将接收端上的推理张量转换为多媒体插件后续可处理的格式，例如视频或文本。<br />c. 对所选数量的结果应用阈值。<br />d. 加载对应分类模型的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载该模型的子模块。<br />  • 以带有分类标签的视频帧形式生成结果。<br />  • 将它们发送到 `qtivcomposer` 的接收端。 |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 分割 | a. 在其接收端接收推理张量。<br />b. 将推理张量转换为多媒体插件后续可处理的视频格式。<br />c. 产生该帧的语义分割。<br />d. 加载对应分割模型的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载 deeplab-argmax 子模块。<br />  • 产生带有分割掩码的视频帧。<br />  • 将它们发送到 `qtivcomposer` 的接收端。        |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) — 姿势 | a. 在其接收端接收推理张量。<br />b. 将推理张量转换为多媒体插件后续可处理的视频格式。<br />c. 对所选数量的结果应用阈值。<br />d. 加载对应各种姿势估计模型的模块。<br />在此用例中，`qtimlpostprocess` 执行以下操作：<br />  • 加载 HRNet 模块。<br />  • 产生带有绘制姿势的视频帧结果。<br />  • 将它们发送到 `qtivcomposer` 的接收端。         |
  | [`qtivcomposer`](https://imsdkdocs.qualcomm.com/plugin-reference/qtivcomposer)              | 1. 使用来自其接收端的内容合成帧。<br />2. 将包含这些合成帧的 GStreamer 缓冲区推送到其源端。                                                                                                                                                                         |
  | [`waylandsink`](https://imsdkdocs.qualcomm.com/plugin-reference/waylandsink)                | 1. 将其接收端接收到的视频流提交给 Weston。<br />2. Weston 将视频流渲染到本地显示器上。                                                                                                                                                                          |

  <h4 id="parallel-inference-config-json-description">
    配置 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` 文件。请更新其属性以匹配您的模型、输入流和输出。有关所有字段，请参阅[**配置 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. 在其接收端接收视频流。<br />2. 对流数据执行以下预处理。当模型期望浮点值作为输入时执行此预处理：<br />   • 颜色转换<br />   • 缩放（放大或缩小）<br />   • 归一化<br />3. 在其源端将预处理后的视频流转换为张量流。<br />该张量流将在管道的后续阶段用于推理。                                                                                                                                              |
  | [`qtimltflite`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimltflite)           | 1. 推理运行时在其接收端接收张量流后，运行推理。<br />2. 在其源端产生包含推理结果的张量流。                                                                                                                                                                                                                                                        |
  | [`qtimlpostprocess`](https://imsdkdocs.qualcomm.com/plugin-reference/qtimlpostprocess) | 处理来自任何对象检测、分类、姿势检测和分割模型的推理结果。<br /><br />**检测用例：**<br />   • 对所选数量的结果应用阈值。<br />   • 加载 YOLOv8 模块。<br />   • 产生仅带有边界框的视频帧，这些边界框可叠加在对象上，并将其发送到 `qtivcomposer` 的接收端。<br /><br />**分类用例：**<br />   • 对所选数量的结果应用阈值。<br />   • 加载 MobileNet-softmax 模块。<br />   • 以带有分类标签的视频帧形式生成结果，并将其发送到 `qtivcomposer` 的接收端。 |
  | [`qtivcomposer`](https://imsdkdocs.qualcomm.com/plugin-reference/qtivcomposer)         | 1. 使用来自其接收端的内容合成帧。<br />2. 将包含这些合成帧的 GStreamer 缓冲区推送到其源端。                                                                                                                                                                                                                                                  |
  | [`waylandsink`](https://imsdkdocs.qualcomm.com/plugin-reference/waylandsink)           | 1. `waylandsink` 将其接收端接收到的视频流提交给 Weston。<br />2. Weston 将视频流渲染到本地显示器上。                                                                                                                                                                                                                                     |
  | `filesink`                                                                             | 1. 在其接收端接收视频流。<br />2. 将流保存为 H.264 编码的 MP4 文件。                                                                                                                                                                                                                                                             |
  | [`qtirtspbin`](https://imsdkdocs.qualcomm.com/plugin-reference/qtirtspbin)             | 1. 作为网络接收器。<br />2. 向网络传输 UDP 数据包。                                                                                                                                                                                                                                                                         |

  <h4 id="multistream-inference-config-json-description">
    配置 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 的示例应用程序。
