ios下使用opencv&C++实现DFT变换

DFT函数源代码:(使用opencv。 using namespace cv)

#pragma mark - DFT
- (cv::Mat)dft2FromMat:(cv::Mat)srcMat 
{    
    // init
    Mat srcMat8uc1(srcMat.rows, srcMat.cols, CV_8UC1);
    cvtColor(srcMat, srcMat8uc1, CV_RGB2GRAY);
    
    Mat MatRe(srcMat.rows, srcMat.cols, CV_64FC1);
    srcMat8uc1.convertTo(MatRe, CV_64F, 1.0/255.0, 0);
    Mat MatIm = Mat::zeros(srcMat.rows, srcMat.cols, CV_64FC1);
    Mat srcMatMerge(srcMat.rows, srcMat.cols, CV_64FC2);
    vector<Mat> mergeVectorOfReAndIm;
    mergeVectorOfReAndIm.push_back(MatRe);
    mergeVectorOfReAndIm.push_back(MatIm);
    merge(mergeVectorOfReAndIm, srcMatMerge);
    
    // Do the work of DFT
    Mat dftMergeOutput(srcMat.rows, srcMat.cols, CV_64FC2);   
    dft(srcMatMerge, dftMergeOutput);
    split(dftMergeOutput, mergeVectorOfReAndIm);
    
    // Re^2 + Im^2 = amplitude^2
    // So you get amplitude here
    Mat tmp1_64fc1 = MatRe.clone();
    Mat tmp2_64fc1 = MatRe.clone();
    pow(MatRe, 2.0, tmp1_64fc1);
    pow(MatIm, 2.0, tmp2_64fc1);
    Mat amplitude = tmp1_64fc1 + tmp2_64fc1;
    pow(amplitude, 0.5, amplitude);
        
    MatRe.release();
    MatIm.release();
    srcMatMerge.release();
    dftMergeOutput.release();
    tmp2_64fc1.release();
    tmp1_64fc1.release();
    srcMat8uc1.release();
        
    return amplitude;
}

效果图如下:

转载于:https://www.cnblogs.com/shawnwho/archive/2013/03/31/2992310.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值