Skip to content

Conversation

@Atari2
Copy link

@Atari2 Atari2 commented Sep 1, 2025

This PR aims to greatly improve performance of the GreyCodePattern algorithm in the StructuredLight module. It does so by caching and pre-calculating a bunch of stuff needed for the computation and instead of doing manual looping and indexing over the matrices it leverages built-in opencv functions to automatically parallelize work (as well as doing some manual parallelization). Additionally, thanks to the fact that it is using opencv functions, it gains the ability to correctly process 16-bit images, which is a plus.

Work done in more detail:

  • Vastly improve performance of the GreyCodePattern structured light algorithm by leveraging built-in OpenCV functions and parallel code instead of raw loops, at the cost of a bit more memory (decoding a set of 96 5320x4600 images acquired using stereo cameras goes from taking ~100 seconds to taking ~2.5 seconds, in release mode)
  • Automatically gain the ability to decode 16-bit images (switching from raw loops and uchar-indexing to OpenCV functions gives this for free)

Manual testing was done to ensure that the calculated results are correct, both for generation of the patterns and for decoding, in both Debug and Release mode, using real world data.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake

@Atari2 Atari2 force-pushed the greycodepattern_improvement_pr branch from b2c445a to bff58b8 Compare September 1, 2025 14:57
…ovements

- Vastly improve performance of the GreyCodePattern structured light algorithm by leveraging built-in OpenCV functions and parallel code instead of raw loops, at the cost of a bit more memory (decoding a set of 96 5320x4600 images acquired using stereo cameras goes from taking ~100 seconds to taking ~2.5 seconds, in release mode)
- Automatically gain the ability to decode 16-bit images (switching from raw loops and uchar-indexing to OpenCV functions gives this for free)

Manual testing was done to ensure that the calculated results are correct, both for generation of the patterns and for decoding, in both Debug and Release mode, using real world data.
@Atari2 Atari2 force-pushed the greycodepattern_improvement_pr branch from bff58b8 to 441c955 Compare September 1, 2025 15:19
@Atari2
Copy link
Author

Atari2 commented Nov 24, 2025

@asmorkalov sorry to ping but I wanted to know if there was any chance for this PR to get looked at or not. I would be very interested in this code ending up in the official release of opencv_contrib

@asmorkalov
Copy link
Contributor

@Atari2 Could you also add some test(s) for the new feature?

…vements regression checks

Created shared plane test logic into test_plane_common.hpp and updated test_plane.cpp and test_plane_16bit.cpp to use the new common template. Created some tests for 16u support and graycode pattern verification in test_graycodepattern_fast.cpp
@Atari2
Copy link
Author

Atari2 commented Nov 25, 2025

Thank you for the review @asmorkalov, sorry again to disturb 😅
I have clarified a bit the two code snippets that you highlighted by adding a small comment and changing a few variable names to make them clearer, hopefully that is enough.

I also added a few tests to verify that the 16-bit images and data are correctly handled. Tell me if you need anything different and if what I added is OK. I see in the github CI that there is 1 run failing but I don't think that it is related to anything that I changed, because I only touched the structured_light submodule.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants