Hi, first post here.
I’m trying to change boxfilter.cpp in order to start understanding npp…
My code is:
#include <npp.h>
#include <ImagesCPU.h>
#include <ImagesNPP.h>
#include <ImageIO.h>
#include <Exceptions.h>
#include <iostream>
int main(int argc, char* argv[])
{
try
{
// if more than one command line arg, use the first arg as the filename,
// otherwise assume the filename included with the sample
const NppLibraryVersion *version = nppGetLibVersion();
fprintf(stderr,"Npp version: %d.%d.%d\n", version->build,version->major,version->minor);
std::string sFilename = "/home/marco/Scrivania/SDK/data/Lena.pgm";
if (argc >= 2)
sFilename = argv[1];
std::string sResultFilename = sFilename;
std::string::size_type dot = sResultFilename.rfind('.');
if (dot != std::string::npos) sResultFilename = sResultFilename.substr(0, dot);
sResultFilename += "_myfilter.pgm";
if (argc >= 3)
sResultFilename = argv[2];
// declare a host image object for an 8-bit grayscale image
npp::ImageCPU_8u_C1 oHostSrc;
// load gray-scale image from disk
npp::loadImage(sFilename, oHostSrc);
// declara a device image and copy construct from the host image,
// i.e. upload host to device
npp::ImageNPP_8u_C1 oDeviceSrc(oHostSrc);
NppiSize oKernelSize = {3,3};
NppiSize oSizeROI = {oDeviceSrc.width() - oKernelSize.width + 1, oDeviceSrc.height() - oKernelSize.height + 1};
const Npp32s hKernel[] = {1,2,3,4,5,6,7,8,9};
Npp32s nDivisor = 9;
NppiPoint oAnchor;
oAnchor.x=0.5*(oKernelSize.width-1);
oAnchor.y=0.5*(oKernelSize.height-1);
npp::ImageNPP_8u_C1 oDeviceDst(oSizeROI.width, oSizeROI.height);
NppStatus eStatusNPP;
eStatusNPP = nppiFilter_8u_C1R(oDeviceSrc.data(), oDeviceSrc.pitch(),oDeviceDst.data(), oDeviceDst.pitch(),oSizeROI,hKernel,oKernelSize,oAnchor,nDivisor);
fprintf(stderr,"Result = %d\n",eStatusNPP);
NPP_ASSERT(NPP_NO_ERROR == eStatusNPP);
// declare a host image for the result
npp::ImageCPU_8u_C1 oHostDst(oDeviceDst.size());
// and copy the device result data into it
oDeviceDst.copyTo(oHostDst.data(), oHostDst.pitch());
saveImage(sResultFilename, oHostDst);
std::cout << "Saved image: " << sResultFilename << std::endl;
}
catch (npp::Exception & rException)
{
std::cerr << "Program error! The following exception occurred: \n";
std::cerr << rException << std::endl;
std::cerr << "Aborting." << std::endl;
return -1;
}
catch (...)
{
std::cerr << "Program error! An unknow type of exception occurred. \n";
std::cerr << "Aborting." << std::endl;
return -1;
}
return 0;
}
The console output is:
Npp version: 0.1.1
Result = -3
Program error! The following exception occurred:
../src/boxFilter.cpp:57: NPP_NO_ERROR == eStatusNPP assertion faild!
Aborting.
Can someone explain me how to make my custom filter working?
Thanks.
Marco