How CuviImage object makes holding images on GPU easier

With CUVI version 0.5 release, significant changes were made to make sure utilizing the power of GPUs for your Imaging and Vision applications is even more easier. In version 0.5, CuviImage object is introduced – it holds image on the GPU so you know whenever you create a CuviImage, the image always resides on the GPU, saving you complexity of creating and managing device memories yourself. In addition to just creating and holding the image on the GPU, CuviImage also maintains the basic information of the image like rows, columns (matrix style), width step, pixel depth, number of channels etc.

Also with the release of version 0.5, the C and C++ interfaces have been clearly separated which means you can call both, the C API functions (declared in the classical “extern ‘C’ ” block) or the C++ functions declared within the cuvi namespace. Every C++ function of CUVI has a C counterpart. Let’s try to look at this with an example:

This is the Optical Flow LK function defined within the “cuvi” namespace.

CUVI_EXPORTS CuviStatus     calcOpticalFlowLK(CuviImage *imgA,
                            CuviImage *imgB,
                            CuviSize winSize,
                            Cuvi32f *&velocityX,
                            Cuvi32f *&velocityY);

And this is it’s plain C counterpart:

CUVI_EXPORTS CuviStatus    cuvi_calcOpticalFlowLK_8u_C1(
                           Cuvi8u *&imgA,
                           Cuvi8u *&imgB,
                           Cuvi32u imageWidth,
                           Cuvi32u imageHeight,
                           CuviSize winSize,
                           Cuvi32f *&u,
                           Cuvi32f *&v);

Notice here that the C++ function takes the CuviImage object as the input images while the C function takes raw data pointers. This is true for every C++ and C function available in CUVI.

How to create a CuviImage object on the GPU

Very simple. Just create it! For example, here I create a 1024×1024, 8bit single-channel image on the GPU:

Now we need to populate this image with the data from the host image (assume that it’s stored in OpenCV’s IplImage object)

With this, the image is now on the GPU and will remain there until you destroy it with:

This release all the resources held by CuviImage so make sure you call it once you’re done with it.