1 #include "fft_opencv.h"
3 void FftOpencv::init(unsigned width, unsigned height, unsigned num_of_feats, unsigned num_of_scales)
9 std::cout << "FFT: OpenCV" << std::endl;
12 void FftOpencv::set_window(const MatDynMem &window)
17 void FftOpencv::forward(const cv::Mat &real_input, ComplexMat &complex_result, float *real_input_arr)
22 cv::dft(real_input, tmp, cv::DFT_COMPLEX_OUTPUT);
23 complex_result = ComplexMat(tmp);
27 void FftOpencv::forward_window(MatDynMem &patch_feats_in, ComplexMat & complex_result, MatDynMem &tmp)
32 uint n_channels = uint(patch_feats.size());
33 for (uint i = 0; i < n_channels; ++i) {
35 cv::dft(patch_feats[i].mul(m_window), complex_res, cv::DFT_COMPLEX_OUTPUT);
36 complex_result.set_channel(int(i), complex_res);
41 void FftOpencv::inverse(ComplexMat & complex_input, MatDynMem & real_result)
43 (void)real_result_arr;
45 if (complex_input.n_channels == 1) {
46 cv::dft(complex_input.to_cv_mat(), real_result, cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
48 std::vector<cv::Mat> mat_channels = complex_input.to_cv_mat_vector();
49 std::vector<cv::Mat> ifft_mats(ulong(complex_input.n_channels));
50 for (uint i = 0; i < uint(complex_input.n_channels); ++i) {
51 cv::dft(mat_channels[i], ifft_mats[i], cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
53 cv::merge(ifft_mats, real_result);
58 FftOpencv::~FftOpencv() {}