]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/fft_opencv.cpp
bb7675734177ce109125b428253021ba92d83c05
[hercules2020/kcf.git] / src / fft_opencv.cpp
1 #include "fft_opencv.h"
2
3 void FftOpencv::init(unsigned width, unsigned height, unsigned num_of_feats, unsigned num_of_scales)
4 {
5     (void)width;
6     (void)height;
7     (void)num_of_feats;
8     (void)num_of_scales;
9     std::cout << "FFT: OpenCV" << std::endl;
10 }
11
12 void FftOpencv::set_window(const MatDynMem &window)
13 {
14     m_window = window;
15 }
16
17 void FftOpencv::forward(const cv::Mat &real_input, ComplexMat &complex_result, float *real_input_arr)
18 {
19     (void)real_input_arr;
20
21     cv::Mat tmp;
22     cv::dft(real_input, tmp, cv::DFT_COMPLEX_OUTPUT);
23     complex_result = ComplexMat(tmp);
24     return;
25 }
26
27 void FftOpencv::forward_window(MatDynMem &patch_feats_in, ComplexMat & complex_result, MatDynMem &tmp)
28 {
29     (void)real_input_arr;
30     (void)fw_all;
31
32     uint n_channels = uint(patch_feats.size());
33     for (uint i = 0; i < n_channels; ++i) {
34         cv::Mat complex_res;
35         cv::dft(patch_feats[i].mul(m_window), complex_res, cv::DFT_COMPLEX_OUTPUT);
36         complex_result.set_channel(int(i), complex_res);
37     }
38     return;
39 }
40
41 void FftOpencv::inverse(ComplexMat &  complex_input, MatDynMem & real_result)
42 {
43     (void)real_result_arr;
44
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);
47     } else {
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);
52         }
53         cv::merge(ifft_mats, real_result);
54     }
55     return;
56 }
57
58 FftOpencv::~FftOpencv() {}