简体   繁体   English

OpenCV傅立叶变换复杂输出问题

[英]OpenCV Fourier Transform complex output issue

I try to do some Fourier analysis, but in the OpenCV cv::dft function the cv::DFT_COMPLEX_OUTPUT seems not working. 我尝试进行一些傅立叶分析,但是在OpenCV cv::dft函数中, cv::DFT_COMPLEX_OUTPUT似乎不起作用。 I do the following: 我执行以下操作:

// Calculate Fourier transform for each time signal
cv::Mat hf, hf_raw, h, h_raw;
cv::Mat Fp(Pt.size[0], Pt.size[1], CV_64FC2);
cv::Mat Fz(Pt.size[0], Pt.size[1], CV_64FC2);

cv::dft(Pt.t(), Fp, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT);
cv::dft(Zt.t(), Fz, cv::DFT_ROWS, cv::DFT_COMPLEX_OUTPUT);



// [DEBUG]
// Fp and Fz has to be (K*4 x WINDOW_LENGTH) size in the current case (24 x 256)
std::cout << "Fp.size: " << Fp.size << std::endl;
// -> OK
// Fp elements should be complx
std::cout << "Fp.type(): " << Fp.type() << std::endl;
// -> Lots of zero at the end!!! -> With cv::DFT_REAL_OUTPUT there are no zeros



cv::Mat nom, denom, W;
cv::mulSpectrums(Fp, Fp, nom, cv::DFT_ROWS, true);
cv::mulSpectrums(Fz, Fz, denom, cv::DFT_ROWS, true);

I declare Fp and Fz to be two channeled in order to hold the real and complex values (on which the cv::mulSpectrums function can operate). 我声明FpFz为两个通道,以保存实数和复数值( cv::mulSpectrums函数可以在其上操作)。 But Fp.type() results in 6 which means the type of the output matrix is CV_64FC1 . 但是Fp.type()结果为6 ,这意味着输出矩阵的类型为CV_64FC1

For the flags the 'or' operator should be used, otherwise the second will be put in a wrong slot! 对于标志,应使用“或”运算符,否则第二个运算符将放在错误的插槽中!

cv::dft(Pt.t(), Fp, cv::DFT_ROWS | cv::DFT_COMPLEX_OUTPUT);
cv::dft(Zt.t(), Fz, cv::DFT_ROWS | cv::DFT_COMPLEX_OUTPUT);

In this case the output will be complex! 在这种情况下,输出将很复杂!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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