common_interfaces icon indicating copy to clipboard operation
common_interfaces copied to clipboard

Enhance NV12 and NV21 Support in sensor_msgs::image_encodings

Open zycczy opened this issue 1 year ago • 2 comments

Description

This pull request introduces significant improvements to the sensor_msgs::image_encodings module in ROS2 Rolling, specifically enhancing support for NV12 and NV21 image encodings. The changes aim to provide more accurate channel definitions, facilitate planar encoding detection, and offer height scaling factors necessary for proper image buffer management.

Changes Made

  1. Redefine numChannels for NV12 and NV21:

    • Updated the numChannels function to return 1 for NV12 and NV21 instead of 2. This change accurately represents their planar YUV 4:2:0 structure, where the image data is split into Y and UV planes.
  2. Add isPlanar Function:

    • Introduced a new utility function isPlanar to check if a given encoding is planar. This function currently identifies NV12, NV21, and NV24 as planar encodings.
    • Usage:
      bool is_planar = sensor_msgs::image_encodings::isPlanar(encoding);
      
  3. Introduce getHeightScaling Function:

    • Added getHeightScaling to provide the height scaling factor for planar encodings. For example, NV21 images with height H will have an actual buffer height of H * 1.5 to accommodate the UV planes.
    • Usage:
      float scaling_factor = sensor_msgs::image_encodings::getHeightScaling(encoding);
      
  4. Correct bitDepth Function:

    • Fixed the bitDepth function to accurately parse and return bit depths for complex encoding strings such as "8UC10".
  5. Code Consistency and Documentation:

    • Unified the handling of planar formats to ensure consistency across different encoding types.
    • Added detailed documentation comments for the newly introduced functions to aid developers in understanding and utilizing them effectively.

zycczy avatar Jan 14 '25 08:01 zycczy

@zycczy could you please follow up on @sloretz's feedback?

Yadunund avatar Feb 06 '25 21:02 Yadunund

@zycczy could you please follow up on @sloretz's feedback?

Sorry for the late reply, Has pushed new changes, these days are Chinese New Year, so I have some days vacation, back to work now

zycczy avatar Feb 10 '25 07:02 zycczy

@sloretz @Yadunund @ahcorde could you please have a review for this PR?

zycczy avatar Apr 01 '25 07:04 zycczy

Pulls: ros2/common_interfaces#264 Gist: https://gist.githubusercontent.com/ahcorde/51a66c824e3b09acaacf3666af403e5d/raw/4932642bb4790d1a78b8b61e483d915659b07b64/ros2.repos BUILD args: --packages-above-and-dependencies sensor_msgs TEST args: --packages-above sensor_msgs ROS Distro: rolling Job: ci_launcher ci_launcher ran: https://ci.ros2.org/job/ci_launcher/15568

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

ahcorde avatar Apr 03 '25 11:04 ahcorde

Hi @ahcorde @sloretz Can we merge this PR? So that next I will work on RQT and image transport NV12 support, the local change has almost done, depends on this PR merge

Thanks. Zhaoyuan

zycczy avatar May 13 '25 02:05 zycczy

@sloretz you already review this PR, do you mind to take another look ?

ahcorde avatar May 15 '25 12:05 ahcorde

  • Linux Build Status
  • Linux-aarch64 Build Status
  • Linux-rhel Build Status
  • Windows Build Status

ahcorde avatar May 15 '25 12:05 ahcorde