Conversion issue between NPP and OpenCV image format

Hi fellas,

I started work with Nvidia Performance Primitives. To be familiar with it, i looked at the sample codes like boxFilter and freeImageInterop. After that, i tried to use an image loaded to memory using OpenCV in NPP. However i can not manage it successfully. I searched and read a lot of forum thread but i can not find any solution to my problem.

I made the sample run flawlessly but the result is not correct. Let’s look at boxFilter sample;

img is my opencv image format which is IplImage* and i want to copy it into pSrcImageCUDA which is in Npp8u* format. They can be seen as same format, however there is a mistake about conversion. I use Lena.pgm which is come with the NPP and it is a 512x512 sized grayscale image.

Npp8u * pSrcImageCUDA;

int nSrcPitchCUDA;

pSrcImageCUDA = nppiMalloc_8u_C1(img->width, img->height, &nSrcPitchCUDA);

	

cudaMemcpy2D(pSrcImageCUDA, nSrcPitchCUDA, img->imageData, 512, img->width, img->height, cudaMemcpyHostToDevice);

And the part where box filter operation takes place. oDeviceSrc is a npp::ImageCPU_8u_C1 object and is created using oHostSrc which reads and keeps the image, i changed oDeviceSrc.data() with pSrcImageCUDA. oDeviceSrc.data() is in Npp8u* format.

eStatusNPP = nppiFilterBox_8u_C1R(pSrcImageCUDA, oDeviceSrc.pitch(), oDeviceDst.data(), oDeviceDst.pitch(), oSizeROI, oMaskSize, oAnchor);

When i looked at the result, i saw that the image’s specific part is box filtered and image is seen as zoomed.

It is a simple try. Where is my mistake? If anybody help me, i really appreciate:)

Hi,

I posted the interoperability of IplImage and FreeImage which can read in Npp8u* among other types on CUVI blog. You may want to take a look at this:
http://blog.cuvilib.com/2010/11/08/how-to-use-opencv-with-cuvi/

Npp8u is another name for “unsigned char” but since IplImage’s imageData returns pointer of type “char” you will have to do an explicit cast like this:

IplImage* OpenCVImage = cvLoadImage(_____);
Npp8u* NPPImage = (Npp8u*)OpenCVImage->imageData;

That’s it!

Hope it works :)

can this image converter do the job for you ? it can covert bewteen various formats.