NPP Image Processing

I´m new in this forums and i have a doubt about Nvidia NPP. I´m working with openCV and i want to integrate NPP to acelerate the computional cost during process images.
I don´t know the function that it moves the web cam´s capture host to the device. I suposse that we have to reserve memory in device with function Malloc and later change the position of the image to device. I have this, but later…??

leftim = cvQueryFrame (leftcam);
rightim = cvQueryFrame (rightcam)

thanks to advance, and sorry for my bad english!


You’re right you need to allocate memory on the device, then transfer each frame from the webcam to the GPU for processing. You can do that either using the CUDA API calls (cudaMalloc / cudaMemcpy2D), or NPP comes with some utility classes (npp::ImageNPP_8u_C1 etc) which have constructors which copy the data from the host.

Bare in mind something I’ve found a few moments ago, that the ImageCPU NPP utility class does not allocate page-locked memory. That means you cannot use the asynchronous transfer functionality in CUDA (cudaMemcpyAsync etc), in my particular case this means I cannot concurrently upload several camera feeds to the GPU.



But i am not sure if using NPP it´s possible to achieve video. I try with CUDA and i´m thinkig that it is correct:

leftim = cvQueryFrame (leftcam);

rightim = cvQueryFrame (rightcam);

IplImage* right_de;

IplImage* left_de;

cudaMalloc((void**)&right_de, 33CV_64F);

cudaMemcpy (right_de,rightim, sizeof(rightim),cudaMemcpyHostToDevice);

cudaMalloc((void**)&left_de, 33CV_64F);

cudaMemcpy (left_de,leftim, sizeof(leftim),cudaMemcpyHostToDevice);

OpenCV includes some functionality that can pull frames from most standard webcams, you will still need that or another SDK to replace it. NPP doesn’t do device interfacing.

Your code is slightly off, but you’re almost there. Don’t think NPP supports 64 bit float images (don’t think Opengl does either, based on the colour range of your monitor). I just wrote this code into the forum, it won’t compile but should give you an idea.

Using NPP:

IplImage *leftim = cvQueryFrame (leftcam);

IplImage *rightim = cvQueryFrame (rightcam);

npp::ImageNPP_32f_C4 *left_de = new npp::ImageNPP_32f_C4 ( leftim.width(), leftim.height() );

npp::ImageNPP_32f_C4 *right_de = new npp::ImageNPP_32f_C4 ( rightim.width(), rightim.height() );

left_de->copyFrom( leftim->imageData, leftim->widthStep );

right_de->copyFrom( rightim->imageData, rightim->widthStep );

Not using NPP:

IplImage *leftim = cvQueryFrame (leftcam);

IplImage *rightim = cvQueryFrame (rightcam);

unsigned char *deviceImgLeft, *deviceImgRight;

cudaMalloc((void**)&deviceImgLeft, leftim->size /* number of bytes of data(), e.g. sizeof ( char ) * channels * width * height */ );

cudaMalloc((void**)&deviceRightLeft, leftim->size /* number of bytes of data(), e.g. sizeof ( char ) * channels * width * height */ );

cudaMemcpy2D( deviceImgLeft, leftim->widthStep, leftim->imageData, leftim->widthStep, leftim->width, leftim->height, cudaMemcpyHostToDevice );

cudaMemcpy2D( deviceImgRight.. );

Sorry if i am very pain about this topic but i´m very interesting. When i do the next:

npp::ImageNPP_32f_C4 *left_de = new npp::ImageNPP_32f_C4 ( 640, 480 );
npp::ImageNPP_32f_C4 *right_de = new npp::ImageNPP_32f_C4 ( 640, 480 );

left_de->copyFrom( leftim->imageData, leftim->widthStep );
right_de->copyFrom( rightim->imageData, rightim->widthStep );

I have an error and i don´t know how to resolv. imageData is defined ‘char’ but copyFrom can´t convert into a npp32f and i don´t know if in NPP exists a function that it does the cast, you know?

thanks to advance and sorry for any disturbance caused

I guessed “ImageNPP_32f_C4”, because in your example you used CV_64 for a type.

npp::ImageNPP_32f_C4 is the 32-bit float 4-channel version of the NPP structures, you need to use the right structure for the type of image that your webcam is loading. For 32-bit float images it will expect the colour values to be normalized between 0 and 1, a floating point value. For instance my cameras load 8-bit char data from the camera, and therefore I use the npp::ImageNPP_8u_C4 structure.

The imageData member is always a pointer to char* data because a char is always 8-bits, 1 byte. In the case of a 32-bit float image you can assume that each 4 elements are a float. Effectively in your case you should be able to cast (npp32f*), as long as the OpenCV image contains normalized float data.

Hope that helps,


What image processing algorithms are you particularly interested in? CUVI Lib - which is an NPP add-on library - offers the following algorithms in addition to the NPP’s functions:

* Optical Flow (Horn & Schunk)
* Optical Flow (Lucan & Kanade)
* Hough Transform
* Hough Lines
* 2D Discrete Wavelet Transform (Haar)
* 2D Discrete Cosine Transform
* RGB2Gray Color Conversion

FYI You can also use the FreeImage library that comes with NPP distribution for image reading and writing.