How do I get the center of connectedComponents with cuda?

Question

System information (version)
  • OpenCV => 4.7.0.72
  • Operating System / Platform => Windows 10
  • Compiler => Visual Studio Code
  • OpenCV extra module => cuda
Detailed description

I’m working on connected component analysis using OpenCV-CUDA, and I want to use the API ‘cv2.cuda.labelComponents’.
According to the official documentation of OpenCV 4.7.0, this API should exist.
However, when I try to use it in Python, I get an attribute error. Is there anyone who has experience using OpenCV-CUDA in Python and can offer an alternative method to obtain the center points of connected components?

Answer
Here there is a python binding in doc

there is no python binding in labelComponents

2 Likes

since that’s in the “cudalegacy” module, I’m betting nobody has bothered annotating/preparing the code so it receives Python bindings generation.

other CUDA modules have Python bindings, so it appears to be doable in principle.

1 Like

Not only is it legacy it was disabled for CUDA >= 8.0. Whilst this does not make the issue on github a bug, it should probably be highlighted in the docs.

Its not all bad news though as cv::cuda::connectedComponents was added in Feb 2022

which does have python bindings.

That said I suspect this won’t be any use to the Walterinuniverisity because there is no CUDA equivalent of cv::connectedComponentsWithStats to retrieve the coordinates of the centre of each connected region.

If they were using C++ I would suggest the NPP libs which have a set of connected component labeling routines, but I would advise caution as I have found them to be buggy and slow.

2 Likes