]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Finish conversion
authorMichal Sojka <michal.sojka@cvut.cz>
Sun, 11 Mar 2018 22:55:19 +0000 (23:55 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Mon, 12 Mar 2018 08:59:41 +0000 (09:59 +0100)
There seems to be some bug in this commit. On TX2, tracking
performance is bad. "Native FFTW" seems to be OK.

src/complexmat.hpp
src/fft_fftw.cpp

index e0330f397c262f1979e9cbb98f339e5e4eccadeb..24877ba3fe7bda046d2d1ad7b053aa5d82fafb9e 100644 (file)
@@ -85,6 +85,23 @@ public:
         return result;
     }
 
+    cv::Mat to_vconcat_mat() const
+    {
+        cv::Mat mat(n_channels*rows, cols, CV_32FC2);
+        for (int ch = 0; ch < n_channels; ++ch) {
+            cv::Mat result(mat, cv::Rect(0, ch*rows, cols, cols));
+            int data_id = 0;
+            for (int y = 0; y < rows; ++y) {
+                T * row_ptr = result.ptr<T>(y);
+                for (int x = 0; x < 2*cols; x += 2){
+                    row_ptr[x] = p_data[ch][data_id].real();
+                    row_ptr[x+1] = p_data[ch][data_id++].imag();
+                }
+            }
+        }
+        return mat;
+    }
+
     //element-wise per channel multiplication, division and addition
     ComplexMat_<T> operator*(const ComplexMat_<T> & rhs) const
     {
index 5fd836ace0b386370e4ca629fbe270aeac3a9eb5..2e1022bbf3bd14a75d5d3985e11508855bd94360 100644 (file)
@@ -84,20 +84,25 @@ ComplexMat Fftw::forward_window(const std::vector<cv::Mat> &input)
 
 cv::Mat Fftw::inverse(const ComplexMat &inputf)
 {
-    cv::Mat real_result;
-
-    std::vector<cv::Mat> mat_channels = inputf.to_cv_mat_vector();
-    std::vector<cv::Mat> ifft_mats(inputf.n_channels);
-    for (int i = 0; i < inputf.n_channels; ++i) {
-        ifft_mats[i].create(m_height, m_width, CV_32F);
-        fftwf_plan plan = fftwf_plan_dft_c2r_2d(m_height, m_width,
-                                                reinterpret_cast<fftwf_complex*>(mat_channels[i].data),
-                                                reinterpret_cast<float*>(ifft_mats[i].data),
-                                                FFTW_ESTIMATE);
-        fftwf_execute(plan);
-        fftwf_destroy_plan(plan);
-    }
-    cv::merge(ifft_mats, real_result);
+    int n_channels = inputf.n_channels;
+    cv::Mat real_result(m_height, m_width, CV_32FC(n_channels));
+    cv::Mat complex_vconcat = inputf.to_vconcat_mat();
+
+    int rank = 2;
+    int n[] = {(int)m_height, (int)m_width};
+    int howmany = n_channels;
+    int idist = m_height*(m_width/2+1), odist = 1;
+    int istride = 1, ostride = n_channels;
+    int *inembed = NULL, *onembed = NULL;
+    fftwf_complex *in = reinterpret_cast<fftwf_complex*>(complex_vconcat.data);
+    float *out = reinterpret_cast<float*>(real_result.data);
+
+    fftwf_plan plan = fftwf_plan_many_dft_c2r(rank, n, howmany,
+                                              in,  inembed, istride, idist,
+                                              out, onembed, ostride, odist,
+                                              FFTW_ESTIMATE);
+    fftwf_execute(plan);
+    fftwf_destroy_plan(plan);
 
     return real_result/(m_width*m_height);
 }