简体   繁体   中英

how to Convert Matlab fft function to cvDft in opencv

I'm Very new to opencv.I need to convert the code from matlab to opencv.i have problem with use fft in matlab.i have a one dimensional matrix a.and i'm going apply fft in that as given below.

a = [0;0;0;0;0;0;0;0;0.09707;0.0998;0.1202;-0.1606;-0.0913;0.1523;0.1288];
c = abs(fft(a,15));
c >>     0.3463
    0.1056
    0.3608
    0.5705
    0.4232
    0.2407
    0.1486
    0.1488
    0.1488
    0.1486
    0.2407
    0.4232
    0.5705
    0.3608
    0.1056

C is my result,which i got from matlab.while i'm going to use cvDFT for this one the results are differnt.please help me with some example..my c code is given below...

CvMat* fftin = cvCreateMat(nn,1,CV_64FC2);
CvMat* fftout = cvCreateMat(nn,1,CV_64FC2);
cvZero(b);    ////consider a hav the value of mat b is  empty for imgin
cvMerge(a,b,NULL,NULL,fftin);
cvDFT(fftin,fftout,CV_DXT_FORWARD,0);
cvSplit(fftout,out_real,out_img,0,0);
    for (int i = 0;i<out_real->rows;i++)
    {
        double val11= cvGetReal2D(out_real,i,0);
        double val12= cvGetReal2D(out_img,i,0);
        val11 = abs(val11);
        val12 = abs(val12);
        printf("DFT value is:%f  %f\n",val11,val12);
        cvSetReal2D(C_out,i,0,val11);
    }

In your first example, you seem to be printing the magnitude of each complex value in the result. But in your second example you seem to be printing the absolute value of each component of the complex values (eg X and Y instead of the length or hypotenuse).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM