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

# Estimate human poses with sample_hrnet_pose_estimation

The `sample_hrnet_pose_estimation` sample application provides high-precision human pose estimation using ROS 2 nodes. It uses Qualcomm® AI Engine Direct SDK (QNN) for model inference.

It processes input images and publishes the following ROS 2 topics:

* `/pose_estimation_results`: Output images with visualized pose keypoints.
* `/pose_estimation_points`: Raw keypoint coordinates in a structured message format.

<Note>
  **Note**

  * For model information, see [HRNetPose - Qualcomm AI Hub](https://aihub.qualcomm.com/iot/models/hrnet_pose?searchTerm=hrnet).
  * For more information, see [sample\_hrnet\_pose\_estimation](https://github.com/qualcomm-qrb-ros/qrb_ros_samples/tree/main/ai_vision/sample_hrnet_pose_estimation) on GitHub.
</Note>

<video
  autoPlay
  muted
  loop
  playsInline
  width={237}
  height={299}
  src="https://mintcdn.com/qualcomm-staging/blZpKs_b9On5nj-y/archives/2.1/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/hrnet_result_image.mp4?fit=max&auto=format&n=blZpKs_b9On5nj-y&q=85&s=605142a2c87ec2db3349aacd7c2c4c79"
  style={{
width: "50%",
display: "block",
margin: "0 auto" }}
  data-path="archives/2.1/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/hrnet_result_image.mp4"
/>

<p style={{ textAlign: 'center', fontWeight: 'bold' }}>
  Figure: Sample effects of `sample_hrnet_pose_estimation`
</p>

## Pipeline flow for `sample_hrnet_pose_estimation`

<img src="https://mintcdn.com/qualcomm-staging/blZpKs_b9On5nj-y/archives/2.1/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/ga1.6-hrnet-pose-estimation.drawio.svg?fit=max&auto=format&n=blZpKs_b9On5nj-y&q=85&s=24ac5435d8239ecfb379fef5913b5ca2" style={{width: "100%"}} width="1259" height="295" data-path="archives/2.1/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/ga1.6-hrnet-pose-estimation.drawio.svg" />

<p style={{ textAlign: 'center', fontWeight: 'bold' }}>
  Figure: Pipeline flow for `sample_hrnet_pose_estimation`
</p>

## ROS nodes used in `sample_hrnet_pose_estimation`

| **ROS node** | **Description** |
| :- | :- |
| [qrb\_ros\_camera](https://github.com/qualcomm-qrb-ros/qrb_ros_camera) | Qualcomm ROS 2 package that captures images with parameters and publishes them to ROS topics. |
| [qrb\_ros\_nn\_inference](https://github.com/qualcomm-qrb-ros/qrb_ros_nn_inference) | Loads a trained AI model, receives preprocessed images, performs inference, and publishes results. |
| [image\_publisher](https://github.com/ros-perception/image_pipeline) | ROS 2 Jazzy package that publishes the image ROS topic with a local path. |
| `hrnet_pose_estimation_node` | Subscribes to `/image_raw` for image input, performs pose estimation, and publishes results to `/pose_estimation_results` and `/pose_estimation_points`. |

## ROS topics used in `sample_hrnet_pose_estimation`

| **ROS Topic** | **Type** | **Published By** |
| :- | :- | :- |
| `/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>
  **Note**

  `/pose_estimation_points` contains the coordinates of 17 key points on the original image. Developers can subscribe to this topic for secondary development. The key points include: nose, left eye, and right eye. The specific correspondence is as follows:

  | ID | Body part | ID | Body part |
  | :-: | :-: | :-: | :-: |
  | 1 | Nose | 10 | Right wrist |
  | 2 | Right eye | 11 | Left wrist |
  | 3 | Left eye | 12 | Right hip |
  | 4 | Right ear | 13 | Left hip |
  | 5 | Left ear | 14 | Right knee |
  | 6 | Right shoulder | 15 | Left knee |
  | 7 | Left shoulder | 16 | Right ankle |
  | 8 | Right elbow | 17 | Left ankle |
  | 9 | Left elbow | | |
</Note>

## Prerequisites

You have completed the settings in [Set up the environment for running sample applications](./set-up-env-for-sample-app).

## Run out-of-the-box `sample_hrnet_pose_estimation`

<Accordion title="Try me">
  <Steps>
    <Step title="Run the sample on the development kit">
      ```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="View the results on the host computer">
      1. Start the `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. Select the following buttons in sequence:
         **Plugins** --> **Visualization** --> **Image View**
      3. Select `pose_estimation_results` to see the results.
      4. Open a new terminal and run the following command to view the `/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>

## Build and run `sample_hrnet_pose_estimation`

The following steps build the `sample_hrnet_pose_estimation` package using Dragonwing IQ-9075 Evaluation Kit as an example.

<Accordion title="Try me">
  <Steps>
    <Step title="Build and package on the host computer">
      1. Build the sample application project.
         ```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. Package and push the sample application to the device.
         ```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="Install and run on the development kit">
      1. Install the sample application.
         ```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. Run the sample application with the steps in [Run out-of-the-box sample\_hrnet\_pose\_estimation](#run-out-of-the-box-sample_hrnet_pose_estimation).
    </Step>
  </Steps>
</Accordion>
