1 #include "fft_opencv.h"
3 void FftOpencv::init(unsigned width, unsigned height, unsigned num_of_feats, unsigned num_of_scales, bool big_batch_mode)
10 std::cout << "FFT: OpenCV" << std::endl;
13 void FftOpencv::set_window(const cv::Mat &window)
18 ComplexMat FftOpencv::forward(const cv::Mat &input)
20 cv::Mat complex_result;
21 cv::dft(input, complex_result, cv::DFT_COMPLEX_OUTPUT);
22 return ComplexMat(complex_result);
25 ComplexMat FftOpencv::forward_window(const std::vector<cv::Mat> &input)
27 int n_channels = input.size();
28 ComplexMat result(input[0].rows, input[0].cols, n_channels);
30 for (int i = 0; i < n_channels; ++i) {
31 cv::Mat complex_result;
32 cv::dft(input[i].mul(m_window), complex_result, cv::DFT_COMPLEX_OUTPUT);
33 result.set_channel(i, complex_result);
38 cv::Mat FftOpencv::inverse(const ComplexMat &input)
41 if (input.n_channels == 1) {
42 cv::dft(input.to_cv_mat(), real_result, cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
44 std::vector<cv::Mat> mat_channels = input.to_cv_mat_vector();
45 std::vector<cv::Mat> ifft_mats(input.n_channels);
46 for (int i = 0; i < input.n_channels; ++i) {
47 cv::dft(mat_channels[i], ifft_mats[i], cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
49 cv::merge(ifft_mats, real_result);
54 float* FftOpencv::inverse_raw(const ComplexMat &input)
59 FftOpencv::~FftOpencv()