]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/blobdiff - src/fft_opencv.cpp
Take current angle into account when updating tracked object position
[hercules2020/kcf.git] / src / fft_opencv.cpp
index e8046ebc94042d4ed41d571cd51e9c713c2c72f7..a41412a37bea4864a1f4fe17706082c36117cf90 100644 (file)
@@ -1,68 +1,47 @@
 #include "fft_opencv.h"
 
-void FftOpencv::init(unsigned width, unsigned height, unsigned num_of_feats, unsigned num_of_scales, bool big_batch_mode)
+void FftOpencv::init(unsigned width, unsigned height, unsigned num_of_feats, unsigned num_of_scales)
 {
-    (void)width;
-    (void)height;
-    (void)num_of_feats;
-    (void)num_of_scales;
-    (void)big_batch_mode;
+    Fft::init(width, height, num_of_feats, num_of_scales);
     std::cout << "FFT: OpenCV" << std::endl;
 }
 
-void FftOpencv::set_window(const cv::Mat &window)
+void FftOpencv::set_window(const MatDynMem &window)
 {
-     m_window = window;
+    m_window = window;
 }
 
-ComplexMat FftOpencv::forward(const cv::Mat &input)
+void FftOpencv::forward(const MatScales &real_input, ComplexMat &complex_result)
 {
-    cv::Mat complex_result;
-    cv::dft(input, complex_result, cv::DFT_COMPLEX_OUTPUT);
-    return ComplexMat(complex_result);
-}
+    Fft::forward(real_input, complex_result);
 
-ComplexMat FftOpencv::forward_raw(float *input, bool all_scales)
-{
-    ComplexMat dummy;
-    return dummy;
+    cv::Mat tmp;
+    cv::dft(real_input.plane(0), tmp, cv::DFT_COMPLEX_OUTPUT);
+    complex_result = ComplexMat(tmp);
 }
 
-ComplexMat FftOpencv::forward_window(const std::vector<cv::Mat> &input)
+void FftOpencv::forward_window(MatScaleFeats &feat, ComplexMat &complex_result, MatScaleFeats &temp)
 {
-    int n_channels = input.size();
-    ComplexMat result(input[0].rows, input[0].cols, n_channels);
-
-    for (int i = 0; i < n_channels; ++i) {
-        cv::Mat complex_result;
-        cv::dft(input[i].mul(m_window), complex_result, cv::DFT_COMPLEX_OUTPUT);
-        result.set_channel(i, complex_result);
-    }
-    return result;
-}
+    Fft::forward_window(feat, complex_result, temp);
 
-cv::Mat FftOpencv::inverse(const ComplexMat &input)
-{
-    cv::Mat real_result;
-    if (input.n_channels == 1) {
-        cv::dft(input.to_cv_mat(), real_result, cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
-    } else {
-        std::vector<cv::Mat> mat_channels = input.to_cv_mat_vector();
-        std::vector<cv::Mat> ifft_mats(input.n_channels);
-        for (int i = 0; i < input.n_channels; ++i) {
-            cv::dft(mat_channels[i], ifft_mats[i], cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
+    for (uint i = 0; i < uint(feat.size[0]); ++i) {
+        for (uint j = 0; j < uint(feat.size[1]); ++j) {
+            cv::Mat complex_res;
+            cv::Mat channel = feat.plane(i, j);
+            cv::dft(channel.mul(m_window), complex_res, cv::DFT_COMPLEX_OUTPUT);
+            complex_result.set_channel(int(j), complex_res);
         }
-        cv::merge(ifft_mats, real_result);
     }
-    return real_result;
 }
 
-float* FftOpencv::inverse_raw(const ComplexMat &input)
-{
-    return nullptr;
-}
-
-FftOpencv::~FftOpencv()
+void FftOpencv::inverse(ComplexMat &  complex_input, MatScales & real_result)
 {
+    Fft::inverse(complex_input, real_result);
 
+    std::vector<cv::Mat> mat_channels = complex_input.to_cv_mat_vector();
+    for (uint i = 0; i < uint(complex_input.n_channels); ++i) {
+        cv::dft(mat_channels[i], real_result.plane(i), cv::DFT_INVERSE | cv::DFT_REAL_OUTPUT | cv::DFT_SCALE);
+    }
 }
+
+FftOpencv::~FftOpencv() {}