QTrk
Public Member Functions | Public Attributes | List of all members
CPUTracker::FFT2D Class Reference

Class to facilitate 2D Fourier transforms. More...

#include <cpu_tracker.h>

Public Member Functions

 FFT2D (int w, int h)
 Initialize the class. More...
 
 ~FFT2D ()
 Free memory and delete the instance. More...
 
void Apply (float *d)
 Apply the 2D FFT. More...
 

Public Attributes

kissfft< float > xfft
 Handle to FFT kissfft instance for x. More...
 
kissfft< float > yfft
 Handle to FFT kissfft instance for y. More...
 
std::complex< float > * cbuf
 Calculation buffer. More...
 

Detailed Description

Class to facilitate 2D Fourier transforms.

Definition at line 99 of file cpu_tracker.h.

Constructor & Destructor Documentation

§ FFT2D()

CPUTracker::FFT2D::FFT2D ( int  w,
int  h 
)
inline

Initialize the class.

Parameters
[in]wImage width.
[in]hImage height.

Definition at line 109 of file cpu_tracker.h.

109 : xfft(w,false), yfft(h,false) {cbuf=new std::complex<float>[w*h]; }
std::complex< float > * cbuf
Calculation buffer.
Definition: cpu_tracker.h:103
kissfft< float > yfft
Handle to FFT kissfft instance for y.
Definition: cpu_tracker.h:102
kissfft< float > xfft
Handle to FFT kissfft instance for x.
Definition: cpu_tracker.h:101

§ ~FFT2D()

CPUTracker::FFT2D::~FFT2D ( )
inline

Free memory and delete the instance.

Definition at line 112 of file cpu_tracker.h.

112 { delete[] cbuf; }
std::complex< float > * cbuf
Calculation buffer.
Definition: cpu_tracker.h:103

Member Function Documentation

§ Apply()

void CPUTracker::FFT2D::Apply ( float *  d)

Apply the 2D FFT.

Parameters
[in,out]dInput array of floats. Output will be put back in this array.

Definition at line 1026 of file cpu_tracker.cpp.

1027 {
1028  int w = xfft.nfft();
1029  int h = yfft.nfft();
1030 
1031  std::complex<float>* tmpsrc = ALLOCA_ARRAY(std::complex<float>, h);
1032  std::complex<float>* tmpdst = ALLOCA_ARRAY(std::complex<float>, h);
1033 
1034  for(int y=0;y<h;y++) {
1035  for (int x=0;x<w;x++)
1036  tmpsrc[x]=d[y*w+x];
1037  xfft.transform(tmpsrc, &cbuf[y*w]);
1038  }
1039  for (int x=0;x<w;x++) {
1040  for (int y=0;y<h;y++)
1041  tmpsrc[y]=cbuf[y*w+x];
1042  yfft.transform(tmpsrc, tmpdst);
1043  for (int y=0;y<h;y++)
1044  cbuf[y*w+x]=tmpdst[y];
1045  }
1046  // copy and shift
1047  for (int y=0;y<h;y++) {
1048  for (int x=0;x<w;x++) {
1049  int dx=(x+w/2)%w;
1050  int dy=(y+h/2)%h;
1051  auto v=cbuf[x+y*w];
1052  d[dx+dy*w] = v.real()*v.real() + v.imag()*v.imag();
1053  }
1054  }
1055 
1056 // delete[] tmpsrc;
1057 // delete[] tmpdst;
1058 }
std::complex< float > * cbuf
Calculation buffer.
Definition: cpu_tracker.h:103
kissfft< float > yfft
Handle to FFT kissfft instance for y.
Definition: cpu_tracker.h:102
#define ALLOCA_ARRAY(T, N)
Definition: std_incl.h:153
kissfft< float > xfft
Handle to FFT kissfft instance for x.
Definition: cpu_tracker.h:101

Member Data Documentation

§ cbuf

std::complex<float>* CPUTracker::FFT2D::cbuf

Calculation buffer.

Definition at line 103 of file cpu_tracker.h.

§ xfft

kissfft<float> CPUTracker::FFT2D::xfft

Handle to FFT kissfft instance for x.

Definition at line 101 of file cpu_tracker.h.

§ yfft

kissfft<float> CPUTracker::FFT2D::yfft

Handle to FFT kissfft instance for y.

Definition at line 102 of file cpu_tracker.h.


The documentation for this class was generated from the following files: