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);
}