public void DFT() { Mat padded = new Mat(); //扩展行宽进行快速,其他位置用0扩充 CvInvoke.CopyMakeBorder(sourceMat, padded, 0, fftRows - sourceMat.Rows, 0, fftCols - sourceMat.Cols, BorderType.Constant, new MCvScalar(0)); //构造虚部 Mat tmp = new Mat(padded.Size, DepthType.Cv32F, 1); tmp.SetTo(new MCvScalar(0)); VectorOfMat planes = new VectorOfMat(padded, tmp); Mat complexI = new Mat(); //多通道混合 CvInvoke.Merge(planes, complexI); //进行DFT变换 CvInvoke.Dft(complexI, complexI, DxtType.Forward, padded.Rows); //将混合的单通道分离实数域虚数域 CvInvoke.Split(complexI, planes); //计算幅度谱,相位谱 CudaInvoke.Magnitude(planes[0], planes[1], magnitudeMat); CudaInvoke.Phase(planes[0], planes[1], phaseMat); magnitudeMat.CopyTo(magPMat); }