> ## Documentation Index
> Fetch the complete documentation index at: https://dragonwingdocs-staging.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> Linux <sup>®</sup> 提供了各种示例应用程序。每个应用程序适用于不同的用例，例如零售、Qualcomm <sup>®</sup> Edge AI Box Solutions 和 IP 摄像头。示例应用程序可分为以下几类：

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

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

开始之前，请设置 [IQ-8275](https://dragonwingdocs.qualcomm.com/Linux/devices/iq8275-evk/set-up-the-device) 设备。

要使用摄像头，请通过在目标设备上运行以下命令在设备上启用 `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-staging/zh/Linux/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="试试看">
  ### 运行应用程序

  <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>

    <Step title="在主机计算机的终端中，运行以下命令以从目标设备提取文件：">
      ```bash theme={null}
      scp root@<IP address of target device>:/etc/media/<filename to pull>
      ```
    </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-staging/zh/Linux/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-staging/zh/Linux/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="试试看">
  ### 运行应用程序

  下表列出了通过 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-staging/zh/Linux/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.sh
  chmod +x download_artifacts.sh
  ./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-staging/zh/Linux/images/run-sample-applications/ai-sample-applications-object-detection-pipeline-flow.svg" alt="Pipeline Diagram" caption="Pipeline Diagram" />

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

<Accordion title="试试看">
  当软件映像包含 **qticamsrc** 插件时，摄像头框架默认使用它。如果没有，则框架将切换为 **libcamera**。由于 Config #1 不支持 **qticamsrc**，因此系统默认为 **libcamera**。

  #### 输入和输出功能

  | 配置        | 文件源 | RTSP | USB 摄像头 | MIPI 摄像头 | IMX577 摄像头 | 文件输出 | 显示 | RTSP 输出 |
  | --------- | --- | ---- | ------- | -------- | ---------- | ---- | -- | ------- |
  | Config #1 | 是   | 是    | 是       | 否        | 是          | 是    | 是  | 是       |
  | Config #2 | 是   | 是    | 是       | 是        | 是          | 是    | 是  | 是       |

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

  | 运行时                            | 模型文件                                                     | 标签文件           |
  | ------------------------------ | -------------------------------------------------------- | -------------- |
  | 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` 参数以匹配摄像头功能，请参阅 [Configure USB camera](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="可用配置">
    <Tabs>
      <Tab title="Config #2">
        摄像头源、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>"
        }
        ```
      </Tab>

      <Tab title="Config #1">
        摄像头源、LiteRT 模型、CPU 运行时

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

        <Note>
          Config #1 仅支持 LiteRT 模型和 CPU 运行时。
        </Note>
      </Tab>
    </Tabs>
  </Accordion>

  #### 预期输出

  检测到的对象带有边界框和标签，覆盖在视频上并显示在本地显示器上。

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/Linux/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">
    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 流接收输入流，为四个用例执行并行推理，并在屏幕上并排显示结果。

<Note>
  此应用程序在 `QLI 2.0` 版本的 `Config #1` 中不受支持，因为不支持 CPU 运行时。
</Note>

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

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/Linux/images/run-sample-applications/gst_ai_parallel_inference_pipeline.svg" alt="Pipeline Diagram" caption="Pipeline Diagram" />

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

<Accordion title="试试看">
  #### 输入和输出功能

  | 配置        | 文件源 | RTSP | USB 摄像头 | MIPI 摄像头 | 文件输出 | 显示 | RTSP 输出 |
  | --------- | --- | ---- | ------- | -------- | ---- | -- | ------- |
  | Config #2 | 是   | 是    | 否       | 是        | 否    | 是  | 否       |

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

  | 运行时    | 模型文件                                                                                                                                                                                             | 标签文件                                                                                                                                                                |
  | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
  | 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="可用配置">
    <Tabs>
      <Tab title="Config #2">
        文件源、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"
        }
        ```
      </Tab>
    </Tabs>
  </Accordion>

  #### 预期输出

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

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/Linux/images/run-sample-applications/expected_output_gst-ai-parallel-inference.png" alt="Pipeline Diagram" caption="Pipeline Diagram" />

  <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">
    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
  <Note>
    此应用程序在 `QLI 2.0` 版本的 `Config #1` 中不受支持，因为不支持 CPU 运行时。
  </Note>
  输出显示在 HDMI 显示器上、保存为 H.264 编码的 MP4 文件，或转换为 RTSP 流。

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

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/Linux/images/run-sample-applications/gst_ai_multistream_inference_pipeline.svg" alt="Pipeline Diagram" caption="Pipeline Diagram" />

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

<Accordion title="试试看">
  #### 输入和输出功能

  | 配置        | 文件源 | RTSP | USB 摄像头 | MIPI 摄像头 | 文件输出 | 显示 | RTSP 输出 |
  | --------- | --- | ---- | ------- | -------- | ---- | -- | ------- |
  | Config #2 | 是   | 是    | 否       | 是        | 是    | 是  | 是       |

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

  | 运行时    | 模型文件                                                                                     | 标签文件                                                               |
  | ------ | ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------ |
  | 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="可用配置">
    <Tabs>
      <Tab title="Config #2">
        对 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
        }
        ```
      </Tab>
    </Tabs>
  </Accordion>

  #### 预期输出

  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-staging/zh/Linux/images/run-sample-applications/multistream.png" alt="Pipeline Diagram" caption="Pipeline Diagram" />

  <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">
    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>
