我正在尝试为 BoxFiltering 创建 NPP 示例,但使用 8 位灰度图像我有 RGBA 二进制数据。我的代码如下所示:
#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;
}
我尝试编译它并得到:
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]
怎么了?你能给我正确的方法吗?
现在我的一段代码看起来像:
// 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);
但现在我不能声明设备映像和复制(最后一行),得到这样的错误:未定义的符号:nppiMalloc_8u_C4。它可以是什么?