I am trying to find bounding boxes for my input data using cuda libraries. I start off with a data set that has noise (and possibly some zeroed out cells) with areas of data that are much higher than the noise.
First I apply a gaussian blur to my data with nppiFilterGauss_32f_C1R.
I then threshold it with nppiCompareC_32f_C1R to create a binary image.
Following this, I use nppiLabelMarkers_8u32u_C1R to create a unique label for each area.
At this point, my results are as I expect. I am left with a dataset that has unique values for each "blob" (although with numeric gaps between the numbers).
I have been looking online and can't seem to find a library that will then find bounding boxes for labeled components on a GPU.
I was able to get the complete flow working with OpenCV using findContours and BoundingRects, but this was doing the work on the CPU and is not able to keep up with my data rate.
Is there a cuda function I am missing that can provide me with the bounding box parameters of each of these labeled blobs?
Thanks!
After the label markers operation, if we then compress the label markers, we can realize a fairly simple approach for identifying bounding boxes, using
atomicMaxandatomicMinin a simple CUDA kernel.Here is a worked example:
Note that if you're going to do this repetetively (for example identifying bounding boxes on video frames) you'll want to get the
cudaMallocoperations mostly out of the performance loop.A typical approach would be to use the methodology that I have already shown for allocation of
bufferin the code above. Only free and reallocate the buffer if the previous size is too small. Likewise for the max and min buffers.