当使用目前最新版本的Cuda 5.0编译opencv_gpu工程时,会出现以下问题:
matrix_reductions.cpp(119) : error C2660: “nppiMean_StdDev_8u_C1R”: 函数不接受 5 个参数
需要修改部分如下:
1: opencv\modules\gpu\src\matrix_reductions.cpp
找到如下函数
void cv::gpu::meanStdDev(const GpuMat& src, Scalar& mean, Scalar& stddev)
原本部分内容为:
DeviceBuffer dbuf(2);
nppSafeCall( nppiMean_StdDev_8u_C1R(src.ptr(), static_cast(src.step), sz, dbuf, (double*)dbuf + 1) );
cudaSafeCall( cudaDeviceSynchronize() );
double* ptrs[2] = {mean.val, stddev.val};
dbuf.download(ptrs);
/**
* 1-channel 8-bit unsigned char image mean and standard deviation.
*
* \param pSrc \ref source_image_pointer.
* \param nSrcStep \ref source_image_line_step.
* \param oSizeROI \ref roi_specification.
* \param pDeviceBuffer Pointer to the required device memory allocation, \ref general_scratch_buffer
* Use \ref nppiMeanStdDevGetBufferHostSize_8u_C1R to determine the minium number of bytes required.
* \param pMean Contains computed mean.
* \param pStdDev Contains computed standard deviation.
* \return \ref image_data_error_codes, \ref roi_error_codes
*/
void cv::gpu::meanStdDev(const GpuMat& src, Scalar& mean, Scalar& stddev)
{
CV_Assert(src.type() == CV_8UC1);
NppiSize sz;
sz.width = src.cols;
sz.height = src.rows;
Npp8u buf;
nppSafeCall( nppiMean_StdDev_8u_C1R(src.ptr(), static_cast(src.step), sz,&buf, mean.val, stddev.val ));
cudaSafeCall( cudaDeviceSynchronize() );
}
找到如下函数
void cv::gpu::rectStdDev(const GpuMat& src, const GpuMat& sqr, GpuMat& dst, const Rect& rect, Stream& s)
原本部分内容为
nppSafeCall( nppiRectStdDev_32s32f_C1R(src.ptr(), static_cast(src.step), (const Npp64f *)sqr.ptr(),static_cast(sqr.step),dst.ptr(), static_cast(dst.step), sz, nppRect) );
nppiRectStdDev_32s32f_C1R第三个参数被换成了const Npp64f *看Cuda定义如下
typedef unsigned char Npp8u; ///< 8-bit unsigned chars
typedef signed char Npp8s; ///< 8-bit signed chars
typedef unsigned short Npp16u; ///< 16-bit unsigned integers
typedef short Npp16s; ///< 16-bit signed integers
typedef unsigned int Npp32u; ///< 32-bit unsigned integers
typedef int Npp32s; ///< 32-bit signed integers
typedef unsigned long long Npp64u; ///< 64-bit unsigned integers
typedef long long Npp64s; ///< 64-bit signed integers
typedef float Npp32f; ///< 32-bit (IEEE) floating-point numbers
typedef double Npp64f; ///< 64-bit floating-point numbers
Npp64f sqr64f = *sqr.ptr();
nppSafeCall( nppiRectStdDev_32s32f_C1R(src.ptr(), static_cast(src.step), &sqr64f, static_cast(sqr.step),
dst.ptr(), static_cast(dst.step), sz, nppRect) );
3:opencv\modules\gpu\src\graphcuts.cpp
找到如下函数
void cv::gpu::graphcut(GpuMat& terminals, GpuMat& leftTransp, GpuMat& rightTransp, GpuMat& top, GpuMat& bottom, GpuMat& labels, GpuMat& buf, Stream& s)
原本部分代码为
nppSafeCall( nppiGraphcut_32s8u(terminals.ptr(), leftTransp.ptr(), rightTransp.ptr(), top.ptr(), bottom.ptr(),static_cast(terminals.step), static_cast(leftTransp.step), sznpp, labels.ptr(), static_cast(labels.step), buf.ptr()) );
#if defined (__cplusplus)
struct NppiGraphcutState;
#else
typedef struct NppiGraphcutState NppiGraphcutState;
#endif
nppSafeCall( nppiGraphcut_32s8u(terminals.ptr(), leftTransp.ptr(), rightTransp.ptr(), top.ptr(), bottom.ptr(),static_cast(terminals.step), static_cast(leftTransp.step), sznpp, labels.ptr(), static_cast(labels.step), (NppiGraphcutState *)buf.ptr()) );
找到如下函数
void cv::gpu::absdiff(const GpuMat& src1, const GpuMat& src2, GpuMat& dst, Stream& s)
原本部分代码为
case CV_32SC1:
nppSafeCall( nppiAbsDiff_32s_C1R(src1.ptr(), static_cast(src1.step), src2.ptr(), static_cast(src2.step), dst.ptr(), static_cast(dst.step), sz) );
break;
完成以上步骤 即可成功编译