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

export const Dragonwing = "Qualcomm® Dragonwing™";

Qualcomm's smart devices, such as the {Dragonwing} IQ-9075 development kits, use NV12 as the default image color space conversion format. However, the more common color space format is RGB888. The `qrb_ros_colorspace_convert` sample application implements the following functionalities:

* Provides ROS nodes

  * API to convert NV12 to RGB888

  * API to convert RGB888 to NV12

* Supports dmabuf fd as input and output

* Input and output image receive and send with QRB ROS transport

* Hardware acceleration with GPU by OpenGL ES

## Pipeline flow for `qrb_ros_colorspace_convert`

The following figure shows the pipeline flow of `qrb_ros_colorspace_convert`.

<Frame caption="qrb_ros_color_space_convert pipeline.">
  <img src="https://mintcdn.com/qualcomm-prod/EDJV-hu6qJhZi4pm/SDKs/QIR-SDK-Ubuntu/images/image19.svg?fit=max&auto=format&n=EDJV-hu6qJhZi4pm&q=85&s=590c7edd58e2944dc655792bba6fa611" alt="Color space conversion pipeline where a custom ROS node exchanges dmabuf fd image buffers with the colorspace_convert node over ROS topics." width="426" height="442" data-path="SDKs/QIR-SDK-Ubuntu/images/image19.svg" />
</Frame>

The following table describes the ROS nodes used in the `qrb_ros_colorspace_convert` software architecture.

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

The following table describes the ROS topics used in the `qrb_ros_colorspace_convert` software architecture.

| ROS topic    | Message type              | Published by/Subscription               | 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, installed ROS2 Jazzy and Qualcomm Intelligent Robotics (QIR) SDK on the device according to [Install the QIR SDK](./install-the-qir-sdk).

* The `custom_ros_node` is ready.

* You have connected the device to the display monitor.

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

<Steps>
  <Step title="Install the color space conversion package according to whether you have installed the desktop or server QIR SDK image">
    See [Install the QIR SDK](./install-the-qir-sdk).

    <Note>
      * `qirp-sdk` is the QIR SDK server image package.
      * `qirp-sdk-desktop` is the QIR SDK desktop image package.
      * For Ventuno Q, use the package listed under **Desktop image**.
    </Note>

    ```bash Server image theme={null}
    sudo apt install ros-jazzy-qrb-ros-colorspace-convert
    ```

    ```bash Desktop image theme={null}
    sudo apt install ros-jazzy-qrb-ros-colorspace-convert-opencv
    ```
  </Step>

  <Step title="Launch the qrb_ros_color_space_convert node">
    ```bash Launch the node theme={null}
    source /opt/ros/jazzy/setup.bash
    # convert color space from NV12 to RGB888
    ros2 launch qrb_ros_colorspace_convert colorspace_convert.launch.py 'conversion_type:=nv12_to_rgb8' 'latency_fps_test:=False'
    # convert color space from RGB888 to NV12
    ros2 launch qrb_ros_colorspace_convert colorspace_convert.launch.py 'conversion_type:=rgb8_to_nv12' 'latency_fps_test:=False'
    ```

    Confirm the color space conversion result with the following commands:

    ```bash theme={null}
    ros2 topic echo /image_raw | grep "encoding"
    ros2 topic echo /image | grep "encoding"
    ```
  </Step>
</Steps>

## Build from source

<Steps>
  <Step title="Install dependencies according to whether you have installed the desktop or server QIR SDK image">
    See [Install the QIR SDK](./install-the-qir-sdk).

    <Note>
      * `qirp-sdk` is the QIR SDK server image package.
      * `qirp-sdk-desktop` is the QIR SDK desktop image package.
      * For Ventuno Q, use the package listed under **Desktop image**.
    </Note>

    ```bash Server image theme={null}
    sudo apt install ros-jazzy-qrb-ros-transport-image-type
    sudo apt install ros-jazzy-qrb-ros-transport-point-cloud2-type
    sudo apt install ros-jazzy-qrb-ros-transport-imu-type
    sudo apt install ros-jazzy-pcl-conversions
    sudo apt install qcom-adreno-dev
    sudo apt install weston
    sudo apt install weston-autostart
    # reboot is required for Weston to start automatically
    ```

    ```bash Desktop image theme={null}
    sudo apt install ros-jazzy-qrb-ros-transport-image-type
    sudo apt install ros-jazzy-qrb-ros-transport-point-cloud2-type
    sudo apt install ros-jazzy-qrb-ros-transport-imu-type
    sudo apt install ros-jazzy-pcl-conversions
    sudo apt install libopencv-dev libopencv-contrib-dev
    ```
  </Step>

  <Step title="Download the source code and build with colcon">
    ```bash Download and build theme={null}
    source /opt/ros/jazzy/setup.bash
    git clone https://github.com/qualcomm-qrb-ros/qrb_ros_color_space_convert.git

    # Server image
    colcon build --cmake-args -DUSE_OPENCV_BACKEND=OFF

    # Desktop image
    colcon build --cmake-args -DUSE_OPENCV_BACKEND=ON
    ```
  </Step>

  <Step title="Run and debug">
    ```bash Run the node theme={null}
    source install/setup.bash
    # convert color space from NV12 to RGB888
    ros2 launch qrb_ros_colorspace_convert colorspace_convert.launch.py 'conversion_type:=nv12_to_rgb8' 'latency_fps_test:=False'
    # convert color space from RGB888 to NV12
    ros2 launch qrb_ros_colorspace_convert colorspace_convert.launch.py 'conversion_type:=rgb8_to_nv12' 'latency_fps_test:=False'
    ```

    Confirm the color space conversion result with the following commands:

    ```bash theme={null}
    ros2 topic echo /image_raw | grep "encoding"
    ros2 topic echo /image | grep "encoding"
    ```
  </Step>
</Steps>
