]> rtime.felk.cvut.cz Git - hercules2020/kcf.git/commitdiff
Merge branch 'master' of github.com:Shanigen/kcf
authorMichal Sojka <michal.sojka@cvut.cz>
Wed, 14 Mar 2018 22:07:50 +0000 (23:07 +0100)
committerMichal Sojka <michal.sojka@cvut.cz>
Wed, 14 Mar 2018 22:07:50 +0000 (23:07 +0100)
1  2 
src/fft_fftw.cpp

index b362ace17cbf2a4e4e8d79c63e7221327aab0496,610ce292d7fd3f5032037594be08099f50cf98cb..07f60abb4385afedfea308dc6bbf3cd57b1a8f57
@@@ -112,33 -105,69 +105,63 @@@ cv::Mat Fftw::inverse(const ComplexMat 
      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[] = {(int)m_height, (int)m_width/2+1}, *onembed = n;
      fftwf_complex *in = reinterpret_cast<fftwf_complex*>(complex_vconcat.data);
      float *out = reinterpret_cast<float*>(real_result.data);
- #if defined(ASYNC) || defined(OPENMP)
-     std::unique_lock<std::mutex> lock(fftw_mut);
-     fftw_plan_with_nthreads(2);
- #endif
-     fftwf_plan plan = fftwf_plan_many_dft_c2r(rank, n, howmany,
-                                               in,  inembed, istride, idist,
-                                               out, onembed, ostride, odist,
-                                               FFTW_ESTIMATE);
+     if(n_channels != 1){
+         if(!plan_if){
+             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;
 -#ifndef CUFFTW
 -            int *inembed = NULL, *onembed = NULL;
 -#else
 -            int inembed[2];
 -            int onembed[2];
 -            inembed[1] = m_width/2+1, onembed[1] = m_width;
 -#endif
++            int inembed[] = {(int)m_height, (int)m_width/2+1}, *onembed = n;
  #ifdef ASYNC
-     lock.unlock();
+             std::unique_lock<std::mutex> lock(fftw_mut);
+             fftw_plan_with_nthreads(2);
+ #elif OPENMP
+ #pragma omp critical
+             fftw_plan_with_nthreads(omp_get_max_threads());
  #endif
-     fftwf_execute(plan);
- #ifdef ASYNC
-     lock.lock();
+ #pragma omp critical
+             plan_if = fftwf_plan_many_dft_c2r(rank, n, howmany,
+                                                          in,  inembed, istride, idist,
+                                                          out, onembed, ostride, odist,
+                                                          FFTW_ESTIMATE);
+             fftwf_execute(plan_if);
+         }else{fftwf_execute_dft_c2r(plan_if,in,out);}
+     }else{
+         if(!plan_ir){
+             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;
+ #ifndef CUFFTW
+             int *inembed = NULL, *onembed = NULL;
+ #else
+             int inembed[2];
+             int onembed[2];
+             inembed[1] = m_width/2+1, onembed[1] = m_width;
  #endif
-     fftwf_destroy_plan(plan);
  #ifdef ASYNC
-     lock.unlock();
+             std::unique_lock<std::mutex> lock(fftw_mut);
+             fftw_plan_with_nthreads(2);
+ #elif OPENMP
+ #pragma omp critical
+             fftw_plan_with_nthreads(omp_get_max_threads());
  #endif
+ #pragma omp critical
+             plan_ir = fftwf_plan_many_dft_c2r(rank, n, howmany,
+                                                          in,  inembed, istride, idist,
+                                                          out, onembed, ostride, odist,
+                                                          FFTW_ESTIMATE);
+             fftwf_execute(plan_ir);
+     }else{fftwf_execute_dft_c2r(plan_ir,in,out);}
+   }
      return real_result/(m_width*m_height);
  }