Cv::floodfill CUDA version

So I don’t reinvent the wheel.

Is there a cv::floodfill CUDA version or equivalent?

Not that I’m aware of I would first check out the performance of npp floodfill. Bear in mind that npp functions can sometimes be slower than you expect so you may find some wheel re-invention necessary.

I switched up to CUDA Toolkit 11.4 but, I am trying to figure out the npp parameters and the mapping to the OpenCV FloodFill equivalent and what the FloodFillGetBufferSize does since I have yet to find an example since it is a new API.

nppiFloodFill_8u_C1IR_Ctx(Npp8u * pSrcDst, int nSrcDstStep, NppiPoint oSeed,
const Npp8u nNewValue, NppiNorm eNorm, NppiSize oSizeROI,
NppiConnectedRegion * pConnectedRegion, Npp8u * pBuffer, NppStreamContext nppStreamCtx); */

				 * 1 channel 8-bit unsigned integer grayscale in place flood fill.
				 * \param pSrcDst  \ref in_place_image_pointer.
				 * \param nSrcDstStep \ref in_place_image_line_step in bytes.
				 * \param oSeed Image location of seed pixel value to be used for comparison.
				 * \param nNewValue Image pixel value to be used to replace matching pixels.
				 * \param eNorm Type of pixel connectivity test to use, nppiNormInf will use 8 way connectivity and nppiNormL1 will use 4 way connectivity.
				 * \param oSizeROI \ref roi_specification.
				 * \param pConnectedRegion Optional host memory pointer to an NppiConnectedRegion object which returns information about the
				 *        filled region. Set to NULL if not needed.
				 * \param pBuffer Pointer to device memory scratch buffer at least as large as value returned by the corresponding FloodFillGetBufferSize call.
				 * \param nppStreamCtx \ref application_managed_stream_context.
				 * \return \ref image_data_error_codes, \ref roi_error_codes

I think I have the mapping close but of course it can’t find the functions in the 11.4 libraries.
Error LNK2001 unresolved external symbol nppiFloodFillGetBufferSize
Error LNK2001 unresolved external symbol nppiFloodFill_8u_C1IR BenchMarkCpp

You need to link to the npp libs. I am not sure which ones you need without checking but if your using visual studio on windows adding the following to Linker->Input->Additional Dependencies


should be enough to remove the linker error. You may then find you get runtime errors because it can be tricky to get the npp parameters correct and as you say there doesn’t appear to be an example in

C:\ProgramData\NVIDIA Corporation\CUDA Samples\v11.4\7_CUDALibraries

I already had all the libraries added to the dependencies and it does not complain it can’t find any of the libraries just that it can find nppiFloodFillGetBufferSize and nppiFloodFill_8u_C1IR .

That’s weird. I just added

NppiSize oSizeROI;
oSizeROI.width = 100; oSizeROI.height = 100;
nt hpBufferSize;
NppStatus sts = nppiFloodFillGetBufferSize(oSizeROI, &hpBufferSize);

to a CUDA project I have and it compiled and ran without an issue on CUDA 11.4.

I wouldn’t expect it to make any difference but did you add the CUDA 11.4 build customization in Visual Studio or did you add the directories manually?

I did the 11.4 selection in visual studio then I had to add the libraries and directories manually.

Prior I had no NPP and was just using OpenCV. The I had to switch from 10.2 to 11.4.

The linker command line is …

/OUT:“E:\source\Erie\BenchMarkCpp\x64\ReleaseCUDA\BenchMarkCpp.exe” /MANIFEST /NXCOMPAT /PDB:“E:\source\Erie\BenchMarkCpp\x64\ReleaseCUDA\BenchMarkCpp.pdb” /DYNAMICBASE “cublas.lib” “cublasLt.lib” “cuda.lib” “cudadevrt.lib” “cudart.lib” “cudart_static.lib” “cufft.lib” “cufftw.lib” “cufilt.lib” “curand.lib” “cusolver.lib” “cusolverMg.lib” “cusparse.lib” “nppc.lib” “nppial.lib” “nppicc.lib” “nppidei.lib” “nppif.lib” “nppig.lib” “nppim.lib” “nppist.lib” “nppisu.lib” “nppitc.lib” “npps.lib” “nvblas.lib” “nvjpeg.lib” “nvml.lib” “nvptxcompiler_static.lib” “nvrtc.lib” “OpenCL.lib” “opencv_cudaarithm349.lib” “opencv_cudabgsegm349.lib” “opencv_cudacodec349.lib” “opencv_cudafeatures2d349.lib” “opencv_cudafilters349.lib” “opencv_cudaimgproc349.lib” “opencv_cudaobjdetect349.lib” “opencv_cudaoptflow349.lib” “opencv_cudastereo349.lib” “opencv_cudawarping349.lib” “opencv_cudev349.lib” “opencv_calib3d349.lib” “opencv_core349.lib” “opencv_dnn349.lib” “opencv_features2d349.lib” “opencv_flann349.lib” “opencv_highgui349.lib” “opencv_imgcodecs349.lib” “opencv_imgproc349.lib” “opencv_ml349.lib” “opencv_objdetect349.lib” “opencv_photo349.lib” “opencv_shape349.lib” “opencv_stitching349.lib” “opencv_superres349.lib” “opencv_video349.lib” “opencv_videoio349.lib” “opencv_videostab349.lib” “ippicvmt.lib” “IlmImf.lib” “ippiw.lib” “ittnotify.lib” “libjasper.lib” “libjpeg-turbo.lib” “libpng.lib” “libprotobuf.lib” “libtiff.lib” “libwebp.lib” “zlib.lib” “kernel32.lib” “user32.lib” “gdi32.lib” “winspool.lib” “comdlg32.lib” “advapi32.lib” “shell32.lib” “ole32.lib” “oleaut32.lib” “uuid.lib” “odbc32.lib” “odbccp32.lib” “E:\source\Erie\BenchMarkCpp\x64\Release\Data.lib” “E:\source\Erie\BenchMarkCpp\x64\ReleaseCUDA\Logging.lib” /DEBUG:FULL /MACHINE:X64 /OPT:REF /INCREMENTAL:NO /PGD:“E:\source\Erie\BenchMarkCpp\x64\ReleaseCUDA\BenchMarkCpp.pgd” /SUBSYSTEM:CONSOLE /MANIFESTUAC:“level=‘asInvoker’ uiAccess=‘false’” /ManifestFile:“x64\ReleaseCUDA\BenchMarkCpp.exe.intermediate.manifest” /OPT:ICF /ERRORREPORT:PROMPT /NOLOGO /LIBPATH:"…\ext\opencv\CUDA\lib\x64" /LIBPATH:"…\ext\opencv\3.4.9\install\x64CUDA\vc15\staticlib" /LIBPATH:“C:\Program Files\NVIDIA GPU Computing Toolkit\CUDA\v11.4\lib\x64” /TLBID:1

Is opencv built with a different version of CUDA? It’s a stretch and I am not sure if it is possible but my thinking is that your static build of opencv may have reference to older versions of the npp libs? Anyway if you haven’t allready I would just create a new project with nppiFloodFillGetBufferSize and see if you can link it by using the 11.4 build customization and adding the npp libs.

Alternatively is it possible you have any old npp libs on the linker paths?