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

# 使用 sample_hrnet_pose_estimation 估计人体姿态

`sample_hrnet_pose_estimation` 示例应用使用 ROS 2 节点提供高精度的人体姿态估计。它使用 Qualcomm® AI Engine Direct SDK (QNN) 进行模型推理。

它处理输入图像并发布以下 ROS 2 topic：

* `/pose_estimation_results`：带有可视化姿态关键点的输出图像。
* `/pose_estimation_points`：以结构化消息格式表示的原始关键点坐标。

<Note>
  **注意**

  * 有关模型信息，请参见 [HRNetPose - Qualcomm AI Hub](https://aihub.qualcomm.com/iot/models/hrnet_pose?searchTerm=hrnet)。
  * 有关更多信息，请参见 GitHub 上的 [sample\_hrnet\_pose\_estimation](https://github.com/qualcomm-qrb-ros/qrb_ros_samples/tree/main/ai_vision/sample_hrnet_pose_estimation)。
</Note>

<video
  autoPlay
  muted
  loop
  playsInline
  width={237}
  height={299}
  src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/hrnet_result_image.mp4"
  style={{
width: "50%",
display: "block",
margin: "0 auto" }}
/>

<p style={{ textAlign: 'center', fontWeight: 'bold' }}>
  图：`sample_hrnet_pose_estimation` 的示例效果
</p>

## `sample_hrnet_pose_estimation` 的流水线流程

<img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/ga1.6-hrnet-pose-estimation.drawio.svg" style={{width: "100%"}} />

<p style={{ textAlign: 'center', fontWeight: 'bold' }}>
  图：`sample_hrnet_pose_estimation` 的流水线流程
</p>

## `sample_hrnet_pose_estimation` 中使用的 ROS 节点

| **ROS 节点**                                                                          | **说明**                                                                                       |
| :---------------------------------------------------------------------------------- | :------------------------------------------------------------------------------------------- |
| [qrb\_ros\_camera](https://github.com/qualcomm-qrb-ros/qrb_ros_camera)              | Qualcomm ROS 2 包，使用参数捕获图像并将其发布到 ROS topic。                                                   |
| [qrb\_ros\_nn\_inference](https://github.com/qualcomm-qrb-ros/qrb_ros_nn_inference) | 加载训练好的 AI 模型，接收预处理后的图像，执行推理并发布结果。                                                            |
| [image\_publisher](https://github.com/ros-perception/image_pipeline)                | ROS 2 Jazzy 包，使用本地路径发布图像 ROS topic。                                                          |
| `hrnet_pose_estimation_node`                                                        | 从 `/image_raw` 订阅图像输入，执行姿态估计，并将结果发布到 `/pose_estimation_results` 和 `/pose_estimation_points`。 |

## `sample_hrnet_pose_estimation` 中使用的 ROS topic

| **ROS topic**                  | **类型**                                    | **发布者**                      |
| :----------------------------- | :---------------------------------------- | :--------------------------- |
| `/image_raw`                   | `sensor_msgs.msg.Image`                   | `qrb_ros_camera`             |
| `/qrb_inference_input_tensor`  | `qrb_ros_tensor_list_msgs.msg.TensorList` | `hrnet_pose_estimation_node` |
| `/qrb_inference_output_tensor` | `qrb_ros_tensor_list_msgs.msg.TensorList` | `qrb_ros_nn_inference`       |
| `/pose_estimation_results`     | `sensor_msgs.msg.Image`                   | `hrnet_pose_estimation_node` |
| `/pose_estimation_points`      | `geometry_msgs.msg.PolygonStamped`        | `hrnet_pose_estimation_node` |

<Note>
  **注意**

  `/pose_estimation_points` 包含原始图像上 17 个关键点的坐标。开发者可以订阅此 topic 进行二次开发。关键点包括：鼻子、左眼和右眼。具体对应关系如下：

  |  ID | 身体部位 |  ID | 身体部位 |
  | :-: | :--: | :-: | :--: |
  |  1  |  鼻子  |  10 |  右手腕 |
  |  2  |  右眼  |  11 |  左手腕 |
  |  3  |  左眼  |  12 |  右髋  |
  |  4  |  右耳  |  13 |  左髋  |
  |  5  |  左耳  |  14 |  右膝  |
  |  6  |  右肩  |  15 |  左膝  |
  |  7  |  左肩  |  16 |  右踝  |
  |  8  |  右肘  |  17 |  左踝  |
  |  9  |  左肘  |     |      |
</Note>

## 前提条件

你已完成 [设置运行示例应用的环境](./set-up-env-for-sample-app) 中的设置。

## 开箱即用运行 `sample_hrnet_pose_estimation`

<Accordion title="试一试">
  <Steps>
    <Step title="在开发套件上运行示例">
      ```bash title="SSH Session" theme={null}
      # Set up the runtime environment
      source /usr/share/qirp-setup.sh -m
      # Set the ROS_DOMAIN_ID
      export ROS_DOMAIN_ID=123
      # Launch the sample with an image publisher. You can replace 'image_path' with the path to your desired image.
      ros2 launch sample_hrnet_pose_estimation launch_with_image_publisher.py image_path:=/usr/ros/jazzy/share/sample_hrnet_pose_estimation/input_image.jpg
      # Launch the sample hrnet pose estimation node with qrb_ros_camera ros node.
      ros2 launch sample_hrnet_pose_estimation launch_with_qrb_ros_camera.py
      ```
    </Step>

    <Step title="在主机计算机上查看结果">
      1. 启动 `rqt`。
         ```bash title="SSH Session" theme={null}
         # YOUR_HOST_IP is the IP address of the Host where you want to view the sample output.
         export DISPLAY=YOUR_HOST_IP:0
         export ROS_DOMAIN_ID=123
         rqt
         ```
      2. 依次选择以下按钮：
         **Plugins** --> **Visualization** --> **Image View**
      3. 选择 `pose_estimation_results` 以查看结果。
      4. 打开一个新终端并运行以下命令以查看 `/pose_estimation_points` topic。
         ```bash title="SSH Session" theme={null}
         source /usr/share/qirp-setup.sh -m
         export ROS_DOMAIN_ID=123
         ros2 topic echo /pose_estimation_points
         ```
    </Step>
  </Steps>
</Accordion>

## 构建并运行 `sample_hrnet_pose_estimation`

以下步骤以 Dragonwing IQ-9075 Evaluation Kit 为例构建 `sample_hrnet_pose_estimation` 包。

<Accordion title="试一试">
  <Steps>
    <Step title="在主机计算机上构建并打包">
      1. 构建示例应用项目。
         ```bash theme={null}
         cd <decompressed_workspace>/images/iq-9075-evk/qirpsdk_artifacts/iq-9075-evk/
         tar -zxvf qirp-sdk_<qirp_version>.tar.gz
         cd qirp-sdk
         source setup.sh
         # build sample
         cd <qirp_decompressed_path>/qirp-samples/ai_vision/sample_hrnet_pose_estimation
         colcon build
         ```
      2. 打包并将示例应用推送到设备。
         ```bash theme={null}
         # package and push build result of sample
         cd <qirp_decompressed_path>/qirp-samples/ai_vision/sample_hrnet_pose_estimation/install/sample_hrnet_pose_estimation
         tar -czvf sample_hrnet_pose_estimation.tar.gz lib share
         scp sample_hrnet_pose_estimation.tar.gz root@[ip-addr]:/opt/
         ```
    </Step>

    <Step title="在开发套件上安装并运行">
      1. 安装示例应用。
         ```bash title="SSH Session" theme={null}
         # Install sample package
         tar --no-overwrite-dir --no-same-owner -zxf /opt/sample_hrnet_pose_estimation.tar.gz -C /usr/ros/jazzy/
         ```
      2. 按照 [开箱即用运行 sample\_hrnet\_pose\_estimation](#run-out-of-the-box-sample_hrnet_pose_estimation) 中的步骤运行示例应用。
    </Step>
  </Steps>
</Accordion>
