> ## 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 示例应用提供高精度的人体姿态估计能力。

`sample_hrnet_pose_estimation` 示例应用提供高精度的人体姿态估计。它处理输入图像，并发布以下 ROS2 话题：

* `/pose_estimation_results`：带有可视化姿态关键点的输出图像。

* `/pose_estimation_points`：以结构化消息格式表示的原始关键点坐标。

<Note>
  有关模型信息，请参阅 [HRNetPose - Qualcomm AI Hub](https://aihub.qualcomm.com/iot/models/hrnet_pose?searchTerm=hrnet)。
</Note>

下图展示了一个姿态估计结果示例。

<Frame>
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-Ubuntu/images/image43.gif" alt="Pose estimation result with a blue skeleton and red keypoints overlaid on a standing person who raises one hand." />
</Frame>

## `sample_hrnet_pose_estimation` 管道流程

下图展示了 `sample_hrnet_pose_estimation` 的管道流程。

<Frame caption="sample_hrnet_pose_estimation 管道。">
  <img src="https://mintlify.s3.us-west-1.amazonaws.com/qualcomm-prod/zh/SDKs/QIR-SDK-Ubuntu/images/image45.svg" alt="Pose estimation pipeline from image input through preprocessing, neural network inference, and postprocessing to keypoint and image outputs." />
</Frame>

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

下表列出了 `sample_hrnet_pose_estimation` 管道中使用的 ROS 节点。

| 节点名                          | 说明                                                                                                                                                          |
| ---------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `hrnet_pose_estimation_node` | 该节点订阅 `/image_raw` 作为图像输入，执行姿态估计，并将结果发布到 `/pose_estimation_results` 和 `/pose_estimation_points` 话题。                                                         |
| `image_publisher_node`       | `image_publisher` 是一个 ROS 2 Jazzy 包，它使用本地路径发布图像 ROS 话题。更多详情请参阅 [image\_publisher](https://github.com/ros-perception/image_pipeline)。                        |
| `qrb_ros_camera`             | QRB ROS Camera 是一个 ROS 包，用于发布来自 Qualcomm CSI 和 GMSL 摄像头的图像。更多详情请参阅 [QRB ROS CAMERA](https://github.com/qualcomm-qrb-ros/qrb_ros_camera)。                    |
| `qrb_ros_nn_inference`       | `qrb_ros_nn_inference` 是一个 ROS 2 包，用于执行神经网络模型，为机器人应用提供基于 AI 的感知能力。更多详情请参阅 [QRB ROS NN Inference](https://github.com/qualcomm-qrb-ros/qrb_ros_nn_inference)。 |

## `sample_hrnet_pose_estimation` 管道中使用的 ROS 话题

下表列出了 `sample_hrnet_pose_estimation` 管道中使用的 ROS 话题。

| ROS 话题                         | 类型                                        | 说明                                    |
| ------------------------------ | ----------------------------------------- | ------------------------------------- |
| `/image_raw`                   | `sensor_msgs.msg.Image`                   | `sample_hrnet_pose_estimation` 的输入图像。 |
| `/qrb_inference_input_tensor`  | `qrb_ros_tensor_list_msgs/msg/TensorList` | 预处理后的图像转换为神经网络推理的输入消息。                |
| `/qrb_inference_output_tensor` | `qrb_ros_tensor_list_msgs/msg/TensorList` | 神经网络推理后的消息。                           |
| `/pose_estimation_results`     | `sensor_msgs.msg.Image`                   | 带有可视化姿态关键点的输出图像。                      |
| `/pose_estimation_points`      | `geometry_msgs.msg.PolygonStamped`        | 以结构化消息格式表示的原始关键点坐标。                   |

<Note>
  `/pose_estimation_points` 包含原始图像上 17 个关键点的坐标。你可以订阅该话题进行二次开发。

  关键点包括：鼻子、左眼和右眼。下图列出了每个关键点 ID 与身体部位的具体对应关系。

  ```text theme={null}
                 (1)
                Nose
               /    \
      (3) L Eye      R Eye (2)
          /              \
   (5) L Ear              R Ear (4)

      (7)                  (6)
  L Shoulder ----------- R Shoulder
       |                      |
      (9)                    (8)
   L Elbow                R Elbow
       |                      |
     (11)                   (10)
   L Wrist                R Wrist

     (13)                   (12)
    L Hip --------------- R Hip
       |                      |
     (15)                   (14)
   L Knee                 R Knee
       |                      |
     (17)                   (16)
   L Ankle                R Ankle
  ```
</Note>

## 前提条件

你已根据[安装 QIR SDK](./install-the-qir-sdk)完成设备设置，并在设备上安装了 ROS2 Jazzy 和 Qualcomm Intelligent Robotics (QIR) SDK。

## 从源码构建 `sample_hrnet_pose_estimation`

当你需要修改示例代码时，可以从源码构建 `sample_hrnet_pose_estimation`。设备端步骤包括安装依赖、克隆源码仓库和构建包。

### 设备步骤

<Steps>
  <Step title="从 qcom 个人包存档 (PPA) 安装依赖 Debian 包">
    ```bash Add the PPAs theme={null}
    sudo add-apt-repository ppa:ubuntu-qcom-iot/qcom-ppa
    sudo add-apt-repository ppa:ubuntu-qcom-iot/qirp
    sudo apt update
    ```
  </Step>

  <Step title="安装 QRB ROS 包">
    ```bash Install the packages theme={null}
    sudo apt install -y ros-jazzy-qrb-ros-camera ros-jazzy-qrb-ros-nn-inference ros-jazzy-qrb-ros-tensor-list-msgs
    sudo apt install -y ros-dev-tools
    sudo rosdep init
    rosdep update
    ```
  </Step>

  <Step title="从 qrb-ros-sample 仓库下载源码">
    ```bash Download the source code theme={null}
    mkdir -p ~/qrb_ros_sample_ws/src && cd ~/qrb_ros_sample_ws/src
    git clone https://github.com/qualcomm-qrb-ros/qrb_ros_samples.git
    ```
  </Step>

  <Step title="下载模型">
    ```bash Download the model theme={null}
    sudo mkdir -p /opt/model && cd /opt/model
    wget https://huggingface.co/qualcomm/HRNetPose/resolve/6011b6e69a84dad8f53fb555b11035a5e26c8755/HRNetPose.bin?download=true -O HRNetPose.bin
    ```
  </Step>

  <Step title="从源码构建示例">
    ```bash Build the sample application theme={null}
    cd ~/qrb_ros_sample_ws/src/qrb_ros_samples/ai_vision/sample_hrnet_pose_estimation
    rosdep install --from-paths . --ignore-src --rosdistro jazzy -y --skip-keys "qrb_ros_tensor_list_msgs qrb_ros_nn_inference qrb_ros_camera"
    source /opt/ros/jazzy/setup.bash
    colcon build
    source install/setup.bash
    ```
  </Step>

  <Step title="在设备上运行示例">
    ```bash Run the sample application theme={null}
    # Launch the sample with 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:=/opt/ros/jazzy/share/sample_hrnet_pose_estimation/input_image.jpg
    # Launch the sample with qrb ros camera.
    ros2 launch sample_hrnet_pose_estimation launch_with_qrb_ros_camera.py
    ```
  </Step>
</Steps>
