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

# Estimate image depth values with sample-depth-estimation

The `sample_depth_estimation` sample application estimates per-pixel depth maps from RGB images using ROS 2 nodes. It uses the Qualcomm® AI Engine Direct SDK (QNN) for on-device model inference.

`sample_depth_estimation` accepts an RGB image named `input_image.jpg` as input or subscribes to the `/sample_container/cam0_stream1` topic from the `qrb_ros_camera` node. It publishes the depth estimation results as a per-pixel depth map to the `/sample_container/depth_map` topic.

<Note>
  **Note**

  * For more information, see the [sample\_depth\_estimation](https://github.com/qualcomm-qrb-ros/qrb_ros_samples/tree/stable-sample_depth_estimation/1.0.0) GitHub repository.
  * This model comes from [Depth Anything V2](https://aihub.qualcomm.com/iot/models/depth_anything_v2?searchTerm=depth\&domain=Computer+Vision), in which depth refers to the distance from the camera to each point in the image, estimated using a deep convolutional neural network.
</Note>

<video
  autoPlay
  muted
  loop
  playsInline
  width={384}
  height={144}
  src="https://mintcdn.com/qualcomm-prod/AeBa_PbSuUY_ELHw/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sample-depth-estimation-output.mp4?fit=max&auto=format&n=AeBa_PbSuUY_ELHw&q=85&s=83a2d1c6e71fa289e9fa9479a7a9560c"
  style={{
width: "80%",
display: "block",
margin: "0 auto"
}}
  data-path="SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sample-depth-estimation-output.mp4"
/>

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

## Pipeline flow for `sample_depth_estimation`

<img
  src="https://mintcdn.com/qualcomm-prod/AeBa_PbSuUY_ELHw/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sample-depth-estimation-pipeline-regenerate.svg?fit=max&auto=format&n=AeBa_PbSuUY_ELHw&q=85&s=1b853f30a63d0291ea7aa5f00fad6f94"
  style={{
width: "100%",
display: "block",
margin: "0 auto" }}
  width="1002"
  height="323"
  data-path="SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/sample-depth-estimation-pipeline-regenerate.svg"
/>

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

## ROS nodes used in the `sample_depth_estimation `pipeline

| ROS Node                  | Description                                                                                                                                                                                               |
| :------------------------ | :-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `sample_depth_estimation` | A Python-based ROS 2 Jazzy package that processes per-pixel depth values. This ROS node subscribes to an image topic, and publishes depth estimation result topic after preprocessing and postprocessing. |
| `qrb_ros_camera`          | Qualcomm ROS 2 package that captures images with parameters and publishes them to ROS topics.                                                                                                             |
| `qrb_ros_nn_inference`    | This ROS node loads a trained AI model, receives preprocessed images, performs inference, and publishes results.                                                                                          |
| `image_publisher`         | A ROS 2 Jazzy package that publishes the image ROS topic with the local path. For more information, see [image\_publisher](https://github.com/ros-perception/image_pipeline).                             |

## ROS topics used in the `sample_depth_estimation `pipeline

<table>
  <thead>
    <tr>
      <th align="center">ROS Topic</th>
      <th align="center">Type</th>
      <th align="center">Description</th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td align="left"><code>/image\_raw</code></td>
      <td align="left"><code>sensor\_msgs.msg.Image</code></td>
      <td align="left">Published image information, from <code>image\_publisher</code>. Subscribed with an absolute name, so it is not namespaced.</td>
    </tr>

    <tr>
      <td align="left"><code>/sample\_container/cam0\_stream1</code></td>
      <td align="left"><code>sensor\_msgs.msg.Image</code></td>
      <td align="left">Camera image stream, from <code>qrb\_ros\_camera</code>.</td>
    </tr>

    <tr>
      <td align="left"><code>/sample\_container/qrb\_inference\_input\_tensor</code></td>
      <td align="left"><code>qrb\_ros\_tensor\_list\_msgs.msg.TensorList</code></td>
      <td align="left">Preprocess message.</td>
    </tr>

    <tr>
      <td align="left"><code>/sample\_container/qrb\_inference\_output\_tensor</code></td>
      <td align="left"><code>qrb\_ros\_tensor\_list\_msgs.msg.TensorList</code></td>
      <td align="left">Postprocess message.</td>
    </tr>

    <tr>
      <td align="left"><code>/sample\_container/depth\_map</code></td>
      <td align="left"><code>sensor\_msgs.msg.Image</code></td>
      <td align="left">Contains per-pixel depth values as a color map.</td>
    </tr>
  </tbody>
</table>

<Note>
  **Note**

  The launch files put every node in the `sample_container` namespace, so the sample's topics are prefixed with `/sample_container/`. Only `/image_raw` is subscribed with an absolute name and therefore stays global.
</Note>

## Prerequisites

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

* Set up the device
* Set up the host docker

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

<Accordion title="Try me">
  <Steps>
    <Step title="Run the sample on the development kit">
      ```bash title="SSH Session" theme={null}
      source /usr/share/qirp-setup.sh -m
      export ROS_DOMAIN_ID=55

      # Launch the sample depth estimation with image publisher.
      # You can replace 'image_path' with your desired image.
      ros2 launch sample_depth_estimation launch_with_image_publisher.py \
          image_path:=/usr/ros/jazzy/share/sample_depth_estimation/resource/input_image.jpg

      # Launch the sample depth estimation node with qrb_ros_camera.
      ros2 launch sample_depth_estimation launch_with_qrb_ros_camera.py
      ```
    </Step>

    <Step title="View the depth estimation result on the host computer">
      1. Start a terminal and run the following command to check the depth estimation result.
         ```bash title="SSH Session" theme={null}
         export ROS_DOMAIN_ID=55
         ros2 topic echo /sample_container/depth_map
         ```
      2. Start the `rqt` to view the depth estimation result on the host docker, for more information, see [rqt](https://wiki.ros.org/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=55
         rqt
         ```
      3. Select the following buttons in sequence. **Plugins** --> **Visualization** --> **Image View**
      4. Select topic `/sample_container/depth_map` by manual on rqt gui, then picture show on `rqt` successfully.
    </Step>
  </Steps>
</Accordion>

## Build and run `sample_depth_estimation`

The following steps build the `sample_depth_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 title="SSH Session" theme={null}
         cd <decompressed_workspace>/images/iq-9075-evk/qirpsdk_artifacts/iq-9075-evk/
         tar -zxvf qirp-sdk_<qirp_version>.tar.gz
         cd <qir_decompressed_path>/qirp-sdk
         source setup.sh
         # build sample
         cd <qirp_decompressed_path>/qirp-samples/ai_vision/sample_depth_estimation
         colcon build
         ```
      2. Package and push the sample application to the device.
         ```bash title="SSH Session" theme={null}
         # package and push build result of sample
         cd ./install/sample_depth_estimation
         tar -czvf sample_depth_estimation.tar.gz lib share
         scp sample_depth_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_depth_estimation.tar.gz -C /usr/ros/jazzy/
         ```
      2. Run the sample application with the steps in [Run out-of-the-box sample\_depth\_estimation](#run-out-of-the-box-sample_depth_estimation).
    </Step>
  </Steps>
</Accordion>
