Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for bayer images to Ogre and Ogre2 #838

Conversation

tejalbarnwal
Copy link
Contributor

@tejalbarnwal tejalbarnwal commented Mar 24, 2023

🎉 New feature

Closes gz-sensors issue 299

Sub-Tasks

  • Support simulation for BAYER_RGGB8 with OGRE
  • Extend the functionality to support all bayer types with OGRE
  • Extend the functionality to support with OGRE2

Summary and Related PRs

The functionality reads the user input and renders an RGB image, which is later converted into a single channel 8bit Bayer image using ConvertRGBToBayer() added to Utils.cc inside gz-rendering.

  • gz-sensors : Adds a switch case for RGGB bayer format inside CameraSensor.cc and passes the R8G8B8 format to render the image.
  • gz-redering : Adds ConvertRGBToBayer() to Utils.cc, modifies OgreRenderTarget.cc to call the conversion function, and handles image format conversion functions with if-else statements.
  • gz-gui : Adds switch cases to display Bayer images in Gazebo GUI inside. It treats them as single-channel 8-bit images.
  • gz-common : Modifies Image::SetFromData inside Image.cc to support saving of Bayer images. In order to save it It treats them as single-channel 8-bit images.

Test it

In order to test this, one can modify camera_sensor.sdf inside gz-sim here. Would have just to replace the part with the following snippet.

<image>
   <width>320</width>
   <height>240</height>
   <format>BAYER_RGGB8</format>
</image>
<clip>
   <near>0.1</near>
   <far>100</far>
</clip>
<save enabled="true">
    <path>path to the folder</path>
</save>

Checklist

  • Signed all commits for DCO
  • Added tests
  • Added example and/or tutorial
  • Updated documentation (as needed)
  • Updated migration guide (as needed)
  • Consider updating Python bindings (if the library has them)
  • codecheck passed (See contributing)
  • All tests passed (See test coverage)
  • While waiting for a review on your PR, please help review another open pull request to support the maintainers

Note to maintainers: Remember to use Squash-Merge and edit the commit message to match the pull request summary while retaining Signed-off-by messages.

Signed-off-by: tejalbarnwal <tejalbarnwal@gmail.com>
Signed-off-by: tejalbarnwal <tejalbarnwal@gmail.com>
@github-actions github-actions bot added the 🌱 garden Ignition Garden label Mar 24, 2023
@azeey
Copy link
Contributor

azeey commented Mar 24, 2023

Since the title of the PR ends up in the changelog, mind changing it to maybe just "Add support for bayer images to Ogre and Ogre2". Feel free to reword, but "Pr" and "gzrendering7" should not be in the title.

@tejalbarnwal tejalbarnwal changed the title Pr gzrendering7 support bayer images Add support for bayer images to Ogre and Ogre2 Mar 24, 2023

// \brief convert a rgb image data into bayer image data
GZ_RENDERING_VISIBLE
void ConvertRGBToBayer(Image &_image);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for global functions, we use a lowercase first letter for the function name. Can you also make this return a copy of the image instead of modifying the source image, i.e. Image convertRGBToBayer(const Image &_image);

Copy link
Contributor Author

@tejalbarnwal tejalbarnwal Mar 28, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I will return the destination image aka the variable destImageData and use memcpy() to actually modify the source image inside OgreRenderTarget.cc. That seems good, right?

src/Utils.cc Outdated Show resolved Hide resolved
@iche033 iche033 added the needs upstream release Blocked by a release of an upstream library label Mar 24, 2023
Signed-off-by: tejalbarnwal <tejalbarnwal@gmail.com>
Signed-off-by: tejalbarnwal <tejalbarnwal@gmail.com>
Comment on lines -46 to +49
/// < Bayer GBGR, 1-byte per channel
PF_BAYER_GBGR8 = 6,
/// < Bayer GRGB, 1-byte per channel
PF_BAYER_GRGB8 = 7,
/// < Bayer GBRG, 1-byte per channel
PF_BAYER_GBRG8 = 6,
/// < Bayer GRBG, 1-byte per channel
PF_BAYER_GRBG8 = 7,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @iche033, I have made the changes to the enum elements corresponding to bayer formats so that they are consistent with gazebo-classic. As you suggested, we could now review the outcomes of the ABI build.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update: The ABI compatibility failed :(

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but looking closely at the report, the compatibility is 100%. It did catch the behavior change, which I'm leaning towards letting it slide since Bayer format was not working before.

Comment on lines -46 to +49
/// < Bayer GBGR, 1-byte per channel
PF_BAYER_GBGR8 = 6,
/// < Bayer GRGB, 1-byte per channel
PF_BAYER_GRGB8 = 7,
/// < Bayer GBRG, 1-byte per channel
PF_BAYER_GBRG8 = 6,
/// < Bayer GRBG, 1-byte per channel
PF_BAYER_GRBG8 = 7,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes but looking closely at the report, the compatibility is 100%. It did catch the behavior change, which I'm leaning towards letting it slide since Bayer format was not working before.

src/Utils.cc Outdated Show resolved Hide resolved
src/Utils.cc Outdated Show resolved Hide resolved
tejalbarnwal and others added 4 commits April 9, 2023 15:30
Signed-off-by: tejalbarnwal <tejalbarnwal@gmail.com>
Signed-off-by: tejalbarnwal <tejalbarnwal@gmail.com>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
@iche033
Copy link
Contributor

iche033 commented Apr 13, 2023

updated channel count of bayer image format from to 4 to 1 and fixed crash in 79a83c6

Signed-off-by: Ian Chen <ichen@openrobotics.org>
Signed-off-by: Ian Chen <ichen@openrobotics.org>
@codecov
Copy link

codecov bot commented Apr 13, 2023

Codecov Report

Merging #838 (2ddecda) into gz-rendering7 (a9e2aba) will decrease coverage by 0.28%.
The diff coverage is 17.46%.

❗ Current head 2ddecda differs from pull request most recent head 40a10b9. Consider uploading reports for the commit 40a10b9 to get more accurate results

@@                Coverage Diff                @@
##           gz-rendering7     #838      +/-   ##
=================================================
- Coverage          77.37%   77.09%   -0.28%     
=================================================
  Files                164      164              
  Lines              14459    14521      +62     
=================================================
+ Hits               11187    11195       +8     
- Misses              3272     3326      +54     
Impacted Files Coverage Δ
src/PixelFormat.cc 100.00% <ø> (ø)
src/Utils.cc 63.63% <0.00%> (-35.19%) ⬇️
ogre2/src/Ogre2RenderTarget.cc 83.44% <68.75%> (-0.67%) ⬇️

... and 1 file with indirect coverage changes

@iche033 iche033 removed the needs upstream release Blocked by a release of an upstream library label May 1, 2023
@iche033 iche033 merged commit 7dc64e5 into gazebosim:gz-rendering7 May 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🌱 garden Ignition Garden
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Bayer images not supported
3 participants