]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blob - src/fft_opencv.cpp
Corrected small mistake with inverse raw in cufft.
[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, bool big_batch_mode)
4 {
5     (void)width;
6     (void)height;
7     (void)num_of_feats;
8     (void)num_of_scales;
9     (void)big_batch_mode;
10     std::cout << "FFT: OpenCV" << std::endl;
11 }
12
13 void FftOpencv::set_window(const cv::Mat &window)
14 {
15      m_window = window;
16 }
17
18 ComplexMat FftOpencv::forward(const cv::Mat &input)
19 {
20     cv::Mat complex_result;
21     cv::dft(input, complex_result, cv::DFT_COMPLEX_OUTPUT);
22     return ComplexMat(complex_result);
23 }
24
25 ComplexMat FftOpencv::forward_window(const std::vector<cv::Mat> &input)
26 {
27     int n_channels = input.size();
28     ComplexMat result(input[0].rows, input[0].cols, n_channels);
29
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);
34     }
35     return result;
36 }
37
38 cv::Mat FftOpencv::inverse(const ComplexMat &input)
39 {
40     cv::Mat real_result;
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);
43     } else {
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);
48         }
49         cv::merge(ifft_mats, real_result);
50     }
51     return real_result;
52 }
53
54 float* FftOpencv::inverse_raw(const ComplexMat &input)
55 {
56     return nullptr;
57 }
58
59 FftOpencv::~FftOpencv()
60 {
61
62 }