title: Different results with cvDFT and DFT in OpenCV 2.4.8
body: <p>I'm having problems with the DFT function in OpenCV 2.4.8 for c++.</p>
  
  <p>I used an image of a 10 phases sinus curve to compare the old cvDFT() with the newer c++ function DFT() (one dimensional DFT row-wise).</p>
  
  <p>The old version gives me logical results: very high peak at pixel 0 and 10, the rest being almost 0.</p>
  
  <p>The new version gives me strange results with peaks all over the spectrum.</p>
  
  <p>Here is my code:</p>
  
  <pre><code>#include "stdafx.h"
  
  #include &lt;opencv2\core\core_c.h&gt;
  #include &lt;opencv2\core\core.hpp&gt;
  #include &lt;opencv2\imgproc\imgproc_c.h&gt;
  #include &lt;opencv2\imgproc\imgproc.hpp&gt;
  #include &lt;opencv2\highgui\highgui_c.h&gt;
  #include &lt;opencv2\highgui\highgui.hpp&gt;
  #include &lt;opencv2\legacy\compat.hpp&gt;
  
  using namespace cv;
  
  
  void OldMakeDFT(Mat original, double* result)
  { 
      const int width = original.cols;
      const int height = 1;
  
      IplImage* fftBlock = cvCreateImage(cvSize(width, height), IPL_DEPTH_8U, 1);
  
      IplImage* imgReal = cvCreateImage(cvSize(width, height), IPL_DEPTH_32F, 1);
      IplImage* imgImag = cvCreateImage(cvSize(width, height), IPL_DEPTH_32F, 1);
      IplImage* imgDFT = cvCreateImage(cvSize(width, height), IPL_DEPTH_32F, 2);
  
      Rect roi(0, 0, width, 1);
      Mat image_roi = original(roi);
      fftBlock-&gt;imageData = (char*)image_roi.data;
  
      //cvSaveImage("C:/fftBlock1.png", fftBlock);
  
      cvConvert(fftBlock, imgReal);     
  
      cvMerge(imgReal, imgImag, NULL, NULL, imgDFT);    
      cvDFT(imgDFT, imgDFT, (CV_DXT_FORWARD | CV_DXT_ROWS));   
  
      cvSplit(imgDFT, imgReal, imgImag, NULL, NULL);    
  
  
      double re,imag;  
      for (int i = 0; i &lt; width; i++)
      { 
          re = ((float*)imgReal-&gt;imageData)[i];
          imag = ((float*)imgImag-&gt;imageData)[i];
          result[i] = re * re + imag * imag;
  
      }  
  
      cvReleaseImage(&amp;imgReal);
      cvReleaseImage(&amp;imgImag);
      cvReleaseImage(&amp;imgDFT);
      cvReleaseImage(&amp;fftBlock);
  }
  
  void MakeDFT(Mat original, double* result)
  {
      const int width = original.cols;
      const int height = 1;
      Mat fftBlock(1,width, CV_8UC1); 
  
      Rect roi(0, 0, width, height);
      Mat image_roi = original(roi);
      image_roi.copyTo(fftBlock);     
  
      //imwrite("C:/fftBlock2.png", fftBlock);
  
      Mat planes[] = {Mat_&lt;float&gt;(fftBlock), Mat::zeros(fftBlock.size(), CV_32F)};
      Mat complexI; 
  
      merge(planes, 2, complexI);     
      dft(complexI, complexI, DFT_ROWS); //also tried with DFT_COMPLEX_OUTPUT | DFT_ROWS
      split(complexI, planes); 
  
      double re, imag; 
      for (int i = 0; i &lt; width; i++)
      {
          re = (float)planes[0].data[i];
          imag = (float)planes[1].data[i];
          result[i] = re * re + imag * imag;      
      } 
  }
  
  
  bool SinusFFTTest()
  { 
      const int size = 1024;
      Mat sinTest(size,size,CV_8UC1, Scalar(0));
      const int n_sin_curves = 10;
      double deg_step = (double)n_sin_curves*360/size;
      for (int j = 0; j &lt; size; j++)
      {
          for (int i = 0; i &lt;size; i++)
          { 
              sinTest.data[j*size+i] = 127.5 * sin(i*deg_step*CV_PI/180) + 127.5; 
          } 
      }
  
      double* result1 = new double[size];
      double* result2 = new double[size];
      OldMakeDFT(sinTest,result1); 
      MakeDFT(sinTest,result2);
      bool identical = true; 
      for (int i = 0; i &lt; size; i++)
      {
          if (abs(result1[i] - result2[i]) &gt; 1000)
          {
              identical = false;
              break;
          }
      }
      delete[] result1;
      delete[] result2;
      return identical;
  }
  
  int _tmain(int argc, _TCHAR* argv[])
  {
      if (SinusFFTTest())
      {
          printf("identical");
      }
      else
      {
          printf("different");
      }
      getchar();
      return 0;
  }
  </code></pre>
  
  <p>Could someone explain the difference?</p>