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

# Convert between NV12 and RGB888 with qrb_ros_colorspace_convert

The `qrb_ros_colorspace_convert` sample application converts between NV12 and RGB888 formats.

Qualcomm's smart devices, such as the Qualcomm Dragonwing<sup>TM</sup> IQ-9075 Evaluation Kit, use NV12 as the default image color space conversion format. However, most ROS 2 image processing nodes expect RGB888. Use `qrb_ros_colorspace_convert` to bridge the two. The `qrb_ros_colorspace_convert` sample application implements the following:

* Converts NV12 to RGB888 through a ROS node API.
* Converts RGB888 to NV12 through a ROS node API.
* Accepts and returns a `dmabuf` file descriptor, so buffers are shared rather than copied.
* Sends and receives images over QRB ROS transport.
* Runs the conversion on the GPU through OpenGL ES.

## Pipeline flow for `qrb_ros_colorspace_convert`

<img src="https://mintcdn.com/qualcomm-prod/Wc1juBQkT-boIg_Z/SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/color-space-convert-pipeline.svg?fit=max&auto=format&n=Wc1juBQkT-boIg_Z&q=85&s=dd0c65cea38976ba2f03f6bdd0352344" style={{width: "90%"}} width="426" height="442" data-path="SDKs/QIR-SDK-2.0/media/80-65220-2-qirp-sdk-qsg/color-space-convert-pipeline.svg" />

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

## ROS nodes used in the `qrb_ros_colorspace_convert `pipeline

|        **ROS Node**       |                                                                     **Description**                                                                    |
| :-----------------------: | :----------------------------------------------------------------------------------------------------------------------------------------------------: |
|     `custom_ros_node`     | `custom_ros_node` is the ROS package that publishes the input image information to the colorspace\_convert\_node. You should implement this ROS2 node. |
| `colorspace_convert_node` |                               `colorspace_convert_node` is a ROS package to convert color space between NV12 and RGB888.                               |

## ROS topics used in the `qrb_ros_colorspace_convert `pipeline

| **ROS topic** |      **Message type**     |       **Published/Subscribed by**      |                   **Description**                  |
| :-----------: | :-----------------------: | :------------------------------------: | :------------------------------------------------: |
|  `/image_raw` | `sensor_msgs::msg::Image` |  Subscribes to images from other nodes |        The input NV12/RGB888 encoded image.        |
|    `/image`   | `sensor_msgs::msg::Image` | Published by `colorspace_convert_node` | Publishes the converted NV12/RGB888 encoded image. |

## Prerequisites

* You have **Set up the device** according to [Set up the environment for running sample applications](./set-up-env-for-sample-app).
* The `custom_ros_node` is ready.
* You have connected the device to the display monitor.

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

<Accordion title="Try me">
  <Steps>
    <Step title="Set up the runtime environment">
      Value range of `ROS_DOMAIN_ID`: \[0, 232]

      ```bash title="SSH Session" theme={null}
      # Set up the runtime environment
      source /usr/share/qirp-setup.sh
      export ROS_DOMAIN_ID=xx
      # Set up the Weston environment
      export XDG_RUNTIME_DIR=/dev/socket/weston/
      mkdir -p $XDG_RUNTIME_DIR
      export WAYLAND_DISPLAY=wayland-1
      # Set up the shared memory
      export FASTRTPS_DEFAULT_PROFILES_FILE=/usr/ros/jazzy/share/qrb_ros_colorspace_convert/config/large_message_profile.xml
      ```
    </Step>

    <Step title="Run the sample qrb_ros_colorspace_convert">
      ```bash title="SSH Session" theme={null}
      # To convert color space from NV12 to RGB888, run the following command
      ros2 launch qrb_ros_colorspace_convert colorspace_convert.launch.py 'conversion_type:=nv12_to_rgb8' 'latency_fps_test:=False'
      # To convert color space from RGB888 to NV12, run the following command
      ros2 launch qrb_ros_colorspace_convert colorspace_convert.launch.py 'conversion_type:=rgb8_to_nv12' 'latency_fps_test:=False'
      ```

      **Result**

      To confirm the conversion, compare the encoding of the input and output topics:

      ```bash title="SSH Session" theme={null}
      ros2 topic echo /image_raw | grep "encoding"
      ros2 topic echo /image | grep "encoding"
      ```

      The two commands report different encodings — one NV12 and one RGB8 — in the direction you selected.
    </Step>
  </Steps>
</Accordion>
