1 #include "fft_opencv.h"
3 void FftOpencv::init(unsigned width, unsigned height, unsigned num_of_feats, unsigned num_of_scales)
5 Fft::init(width, height, num_of_feats, num_of_scales);
6 std::cout << "FFT: OpenCV" << std::endl;
9 void FftOpencv::set_window(const MatDynMem &window)
14 void FftOpencv::forward(const MatScales &real_input, ComplexMat &complex_result)
16 Fft::forward(real_input, complex_result);
19 cv::dft(real_input.plane(0), tmp, cv::DFT_COMPLEX_OUTPUT);
20 complex_result = ComplexMat(tmp);
23 void FftOpencv::forward_window(MatScaleFeats &feat, ComplexMat &complex_result, MatScaleFeats &temp)
25 Fft::forward_window(feat, complex_result, temp);
27 uint n_channels = feat.size[0];
28 for (uint i = 0; i < n_channels; ++i) {
29 for (uint j = 0; j < uint(feat.size[1]); ++j) {
31 cv::Mat channel = feat.plane(i, j);
32 cv::dft(channel.mul(m_window), complex_res, cv::DFT_COMPLEX_OUTPUT);
33 complex_result.set_channel(int(i), complex_res);
38 void FftOpencv::inverse(ComplexMat & complex_input, MatScales & real_result)
40 Fft::inverse(complex_input, real_result);
42 if (complex_input.n_channels == 1) {
43 cv::dft(complex_input.to_cv_mat(), real_result.plane(0), cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
45 std::vector<cv::Mat> mat_channels = complex_input.to_cv_mat_vector();
46 std::vector<cv::Mat> ifft_mats(ulong(complex_input.n_channels));
47 for (uint i = 0; i < uint(complex_input.n_channels); ++i) {
48 cv::dft(mat_channels[i], ifft_mats[i], cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
50 cv::merge(ifft_mats, real_result);
54 FftOpencv::~FftOpencv() {}