cuda::connectedComponents random label numbers?

I want moments for the connected component having the greatest area, but I can’t see an elegant way to locate said component given label numbering seems to be random 32 bit integers. Any suggestions?

opencv 4.9.0

I’m suprised I would have expected it to be the lowest indexed pixel in the blob.

If you need a structure similar to the CPU version I would use NPP, otherwise you have to write your own routine to compress the labels and extract the blob info. See NPP CompressedMarkerLabelsUFInfo for details.

Notes regarding NPP:

  1. You need to use CUDA 12.3 as there was a bug in the NPP routine which returned the info in earlier versions.
  2. The NPP version doesn’t label the background (0 intensity pixels) as 0 which is the expected behaviour in OpenCV.

Thank you for the response.

That appears to be the background, which in my use case is indeed the largest area, but of no interest.

I’ll look at NPP: It would be really sweet if connectedComponents could be made to produce sequential labels starting at 0…