程序如下:
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
#include "cuda_runtime.h"
#include
#include
#include "ImgPro_cu.cU"
using namespace std;
using namespace cv;
extern "C"
double cudaMSR_RGB(
BYTE* pImgOut,
BYTE* pImgIn,
int nWidth,
int nHeight,
int nWidthStep)
{
int FilterWidth = nWidth;
int FilterHeight = nHeight;
float sigma = 300;
int DataBits = 8;
int fftW = nWidth;
int fftH = nHeight;
float *h_pDataSrcRGB = NULL;
float *h_pDataDst= NULL;
float *h_pKernel= NULL;
float *d_Kernel= NULL;
float *d_DataSrc= NULL;
float *d_DataDst= NULL;
fComplex *d_DataSpectrum;
fComplex *d_KernelSpectrum;
h_pDataSrcRGB = (float*)malloc(nWidth*nHeight*sizeof(float));
h_pDataDst = (float*)malloc(nWidth*nHeight*sizeof(float));
h_pKernel = (float*)malloc(FilterWidth*FilterHeight*sizeof(float));
cudaMalloc((void **)&d_Kernel, FilterWidth*FilterHeight*sizeof(float));
cudaMalloc((void **)&d_DataSrc,nWidth*nHeight*sizeof(float) );
cudaMalloc((void **)&d_DataDst,nWidth*nHeight*sizeof(float) );
cudaMalloc((void **)&d_DataSpectrum , fftH*(fftW/2+1)*sizeof(fComplex) );
cudaMalloc((void **)&d_KernelSpectrum, fftH*(fftW/2+1)*sizeof(fComplex) );
memset(h_pDataSrcRGB,0,nWidth*nHeight*sizeof(float));
memset(h_pDataDst, 0, nWidth*nHeight*sizeof(float));
memset(h_pKernel , 0, FilterWidth*FilterHeight*sizeof(float));
cudaMemset(d_Kernel, 0, FilterWidth*FilterHeight*sizeof(float));
cudaMemset(d_DataSrc, 0, nWidth*nHeight*sizeof(float));
cudaMemset(d_DataDst, 0, nWidth*nHeight*sizeof(float));
cudaMemset(d_DataSpectrum , 0, fftH*(fftW/2+1)*sizeof(fComplex));
cudaMemset(d_KernelSpectrum, 0, fftH*(fftW/2+1)*sizeof(fComplex));
//产生高斯滤波器
GaussFilter(h_pKernel, sigma, FilterWidth, FilterHeight);
//定义傅里叶变换
cufftHandle fftPlanFwd, fftPlanInv;
cufftPlan2d(&fftPlanFwd, nHeight, nWidth, CUFFT_R2C);
cufftPlan2d(&fftPlanInv, nHeight, nWidth, CUFFT_C2R);
//计时开始
clock_t start, finish;
double dDuration = 0.0;
start = clock();
for (int i_Channel = 1;i_Channel<=3;i_Channel++)
{
for (int y = 0; y < nHeight; y++)
{
for (int x=0;x<nWidth;x++)
{
h_pDataSrcRGB[y * nWidth + x ] = pImgIn[y * nWidthStep + 3*x + i_Channel];//RGB三个通道
}
}
cudaMemcpy(d_DataSrc, h_pDataSrcRGB, nWidth*nHeight*sizeof(float),
cudaMemcpyHostToDevice);
cudaMemcpy(d_Kernel, h_pKernel, nWidth*nHeight*sizeof(float),
cudaMemcpyHostToDevice);
//执行傅里叶正变换
cufftExecR2C(fftPlanFwd, d_DataSrc, (cufftComplex *)d_DataSpectrum);
cufftExecR2C(fftPlanFwd, d_Kernel , (cufftComplex *)d_KernelSpectrum);
//频域数据点乘
modulateAndNormalize(d_DataSpectrum, d_KernelSpectrum, fftH, fftW);
//执行傅里叶逆变换
cufftExecC2R(fftPlanInv, (cufftComplex *)d_DataSpectrum, d_DataDst);
//图像高频增强
High_Frequency_Enhancer(d_DataDst, d_DataSrc, nWidth, nHeight);
//图像灰度拉伸映射
cudaMemcpy(d_DataSrc, d_DataDst, nWidth*nHeight*sizeof(float),
cudaMemcpyDeviceToDevice);
float Vmax = GetMaxValue(d_DataSrc, nWidth*nHeight);
cudaMemcpy(d_DataSrc, d_DataDst, nWidth*nHeight*sizeof(float),
cudaMemcpyDeviceToDevice);
float Vmin = GetMinValue(d_DataSrc, nWidth*nHeight);
GrayReset(d_DataDst, d_DataDst, nWidth, nHeight, Vmax, Vmin, DataBits);
cudaMemcpy(h_pDataDst, d_DataDst, nWidth*nHeight*sizeof(float),
cudaMemcpyDeviceToHost);
for (int x=0;x<nWidth*nHeight;x++)
{
pImgOut[3*x+i_Channel] = h_pDataDst[x] ;//RGB三个通道
}
}
//计时结束
finish = clock();
dDuration = (double)(finish - start) / CLOCKS_PER_SEC;
cufftDestroy(fftPlanFwd);
cufftDestroy(fftPlanInv);
free(h_pDataSrcRGB);
free(h_pDataDst);
free(h_pKernel);
cudaFree(d_DataSrc);
cudaFree(d_DataDst);
cudaFree(d_Kernel);
cudaFree(d_DataSpectrum);
cudaFree(d_KernelSpectrum);
return dDuration;
}
int main()
{
IplImage *src = cvLoadImage("22.jpg");
IplImage *dst = cvCloneImage( src );
BYTE* srcdata = (BYTE *) src->imageData;
int nWidth = src->width;
int nHeight = src->height;
int nWidthStep = src->widthStep;
BYTE* dstdata = (BYTE *) dst->imageData;
cudaMSR_RGB(srcdata, dstdata,nWidth,nHeight,nWidthStep);
cvNamedWindow("原画",0);
cvShowImage("原画",src);
cvNamedWindow("色彩还原",0);
cvShowImage("色彩还原",dst);
cvWaitKey(0);
cvDestroyAllWindows();
cvReleaseImage(&src);
}
运行后显示如下:
1>Laplacian.cu.obj : error LNK2019: 无法解析的外部符号 _cufftDestroy@4,该符号在函数 "void __cdecl ConvolutionFFT(float *,float *,float *,int,int,int,int)" (?ConvolutionFFT@@YAXPAM00HHHH@Z) 中被引用
1>Laplacian.cu.obj : error LNK2019: 无法解析的外部符号 _cufftExecC2R@12,该符号在函数 "void __cdecl ConvolutionFFT(float *,float *,float *,int,int,int,int)" (?ConvolutionFFT@@YAXPAM00HHHH@Z) 中被引用
1>Laplacian.cu.obj : error LNK2019: 无法解析的外部符号 _cufftExecR2C@12,该符号在函数 "void __cdecl ConvolutionFFT(float *,float *,float *,int,int,int,int)" (?ConvolutionFFT@@YAXPAM00HHHH@Z) 中被引用
1>Laplacian.cu.obj : error LNK2019: 无法解析的外部符号 _cufftPlan2d@16,该符号在函数 "void __cdecl ConvolutionFFT(float *,float *,float *,int,int,int,int)" (?ConvolutionFFT@@YAXPAM00HHHH@Z) 中被引用
1>C:\Users\Xu\Desktop\Laplacian\Vibe\Debug\Laplacian.exe : fatal error LNK1120: 4 个无法解析的外部命令
求问大神怎么解决这个问题。万分感谢