I'm trying to create NPP example for BoxFiltering but insted of 8-bit greyscale image I have RGBA binary data. My code looks like:
#include "./common/ImagesCPU.h"
#include "./common/ImagesNPP.h"
#include "./common/ImageIO.h"
#include "./common/Exceptions.h"
#include <npp.h>
void boxfilter_transform( Npp8u *oHostSrc, int width, int height ){
size_t size = width * height * 4;
// declare a device image and copy construct from the host image,
// i.e. upload host to device
npp::ImageNPP_8u_C4 oDeviceSrc(oHostSrc);
// create struct with box-filter mask size
NppiSize oMaskSize = {5, 5};
// create struct with ROI size given the current mask
NppiSize oSizeROI = {oDeviceSrc.width() - oMaskSize.width + 1, oDeviceSrc.height() - oMaskSize.height + 1};
// allocate device image of appropriatedly reduced size
npp::ImageNPP_8u_C4 oDeviceDst(oSizeROI.width, oSizeROI.height);
// set anchor point inside the mask to (0, 0)
NppiPoint oAnchor = {0, 0};
// run box filter
NppStatus eStatusNPP;
eStatusNPP = nppiFilterBox_8u_C4R(oDeviceSrc.data(), oDeviceSrc.pitch(),
oDeviceDst.data(), oDeviceDst.pitch(),
oSizeROI, oMaskSize, oAnchor);
NPP_ASSERT(NPP_NO_ERROR == eStatusNPP);
// declare a host image for the result
npp::ImageCPU_8u_C4 oHostDst(oDeviceDst.size());
// and copy the device result data into it
oDeviceDst.copyTo(oHostDst.data(), oHostDst.pitch());
return 0;
}
I try to compile it and get:
npp_filters.cpp: In function ‘void boxfilter_transform(Npp8u*, int, int)’:
npp_filters.cpp:18:44: error: no matching function for call to ‘npp::ImageNPP<unsigned char, 4u>::ImageNPP(Npp8u*&)’
npp_filters.cpp:18:44: note: candidates are:
./common/ImagesNPP.h:52:13: note: template<class X> npp::ImageNPP::ImageNPP(const npp::ImageCPU<D, N, X>&, bool)
./common/ImagesNPP.h:45:13: note: npp::ImageNPP<D, N>::ImageNPP(const npp::ImageNPP<D, N>&) [with D = unsigned char, unsigned int N = 4u]
./common/ImagesNPP.h:45:13: note: no known conversion for argument 1 from ‘Npp8u* {aka unsigned char*}’ to ‘const npp::ImageNPP<unsigned char, 4u>&’
./common/ImagesNPP.h:40:13: note: npp::ImageNPP<D, N>::ImageNPP(const npp::Image::Size&) [with D = unsigned char, unsigned int N = 4u]
./common/ImagesNPP.h:40:13: note: no known conversion for argument 1 from ‘Npp8u* {aka unsigned char*}’ to ‘const npp::Image::Size&’
./common/ImagesNPP.h:35:13: note: npp::ImageNPP<D, N>::ImageNPP(unsigned int, unsigned int, bool) [with D = unsigned char, unsigned int N = 4u]
./common/ImagesNPP.h:35:13: note: candidate expects 3 arguments, 1 provided
./common/ImagesNPP.h:30:13: note: npp::ImageNPP<D, N>::ImageNPP() [with D = unsigned char, unsigned int N = 4u]
./common/ImagesNPP.h:30:13: note: candidate expects 0 arguments, 1 provided
npp_filters.cpp:39:12: error: return-statement with a value, in function returning 'void' [-fpermissive]
What is wrong? Can you give me the right way?
Now my piece of code looks like:
// declare a host image object for an 8-bit RGBA image
npp::ImageCPU_8u_C4 oHostSrc(width, height);
// copy data to oHostSrc.data()
Npp8u *nDstData = oHostSrc.data();
memcpy(nDstData, data, size * sizeof(Npp8u));
// declare a device image and copy construct from the host image,
// i.e. upload host to device
npp::ImageNPP_8u_C4 oDeviceSrc(oHostSrc);
but now I can't declare a device image and copy (last line), get such error: undefined symbol: nppiMalloc_8u_C4. What it can be?
There's no constructor in
npp::ImageNPP_8u_C4
for a single host pointer, you need first to wrap the host array in anpp::ImageCPU_8u_C4
like it is done for example in the ImageIO.h you included. The point is, that your NPP-image needs to get some dimension information, which you are currently missing foroDeviceSrc
.