title: Convert OpenCv DFT example from C++ to Android
body: <p>I want to implement follwoing OpenCV example in a Android app:</p>
  
  <p><a href="http://docs.opencv.org/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.html" rel="nofollow">http://docs.opencv.org/doc/tutorials/core/discrete_fourier_transform/discrete_fourier_transform.html</a></p>
  
  <p>My code is the foll0wing:</p>
  
  <pre><code>        //First convert Bitmap to Mat
          Mat ImageMat = new Mat ( image.getHeight(), image.getWidth(), CvType.CV_64FC1, new Scalar(4));
          Bitmap myBitmap32 = image.copy(Bitmap.Config.ARGB_8888, true);
          Utils.bitmapToMat(myBitmap32, ImageMat);
  
  
          Imgproc.cvtColor(ImageMat, ImageMat, Imgproc.COLOR_RGB2GRAY);
  
          Mat padded = new Mat(CvType.CV_64FC1);                            //expand input image to optimal size
          int m = Core.getOptimalDFTSize(ImageMat.rows());
          int n = Core.getOptimalDFTSize(ImageMat.cols()); // on the border add zero values
          Imgproc.copyMakeBorder(ImageMat, padded, 0, m - ImageMat.rows(), 0, n - ImageMat.cols(), Imgproc.BORDER_CONSTANT);
  
          List&lt;Mat&gt; planes = new ArrayList&lt;Mat&gt;();
          planes.add(padded);
          planes.add(Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1));
  
          Mat complexI = Mat.zeros(padded.rows(), padded.cols(), CvType.CV_64FC1);
  
          Core.merge(planes, complexI);         // Add to the expanded another plane with zeros
  
          Core.dft(complexI, complexI);            // this way the result may fit in the source matrix
  
          // compute the magnitude and switch to logarithmic scale
          // =&gt; log(1 + sqrt(Re(DFT(I))^2 + Im(DFT(I))^2))
          Core.split(complexI, planes);                   // planes[0] = Re(DFT(I), planes[1] = Im(DFT(I))
          Core.magnitude(planes.get(0), planes.get(1), planes.get(1));// planes[0] = magnitude
          Mat magI = planes.get(0);
  
          Core.add(magI, Mat.ones(padded.rows(), padded.cols(), CvType.CV_64FC1), magI);                 // switch to logarithmic scale
          Core.log(magI, magI);
  
  
          Mat crop = new Mat(magI, new Rect(0, 0, magI.cols() &amp; -2, magI.rows() &amp; -2));
  
          magI = crop.clone();
  
          // rearrange the quadrants of Fourier image  so that the origin is at the image center
          int cx = magI.cols()/2;
          int cy = magI.rows()/2;
  
  
          Rect q0Rect = new Rect (0, 0, cx, cy);
          Rect q1Rect = new Rect (cx, 0, cx, cy);
          Rect q2Rect = new Rect (0, cy, cx, cy);
          Rect q3Rect = new Rect (cx, cy, cx, cy);
  
          Mat q0 = new Mat(magI, q0Rect);   // Top-Left - Create a ROI per quadrant
          Mat q1 = new Mat(magI, q1Rect);  // Top-Right
          Mat q2 = new Mat(magI, q2Rect);  // Bottom-Left
          Mat q3 = new Mat(magI, q3Rect); // Bottom-Right
  
          Mat tmp = new Mat();                           // swap quadrants (Top-Left with Bottom-Right)
          q0.copyTo(tmp);
          q3.copyTo(q0);
          tmp.copyTo(q3);
  
          q1.copyTo(tmp);                    // swap quadrant (Top-Right with Bottom-Left)
          q2.copyTo(q1);
          tmp.copyTo(q2);
  
          Core.normalize(magI, magI, 0, 1, Core.NORM_MINMAX);
  
          Mat realResult = new Mat();
          magI.convertTo(realResult, CvType.CV_64FC1);
  
  
  
  
          //Then convert the processed Mat to Bitmap
          Bitmap resultBitmap = Bitmap.createBitmap(ImageMat.cols(),  ImageMat.rows(),Bitmap.Config.ARGB_8888);;
          Utils.matToBitmap(ImageMat, resultBitmap);
  
          //Set member to the Result Bitmap. This member is displayed in an ImageView
          mResult = resultBitmap;
  </code></pre>
  
  <p>(note: <code>image</code> is the Input Bitmap and <code>mResult</code> is the output bitmap that is shown in a ImageView)</p>
  
  <p>I get the following error:</p>
  
  <blockquote>
    <p>Error: 08-08 12:17:36.207: A/libc(1594): Fatal signal 11 (SIGSEGV) at 0x0000000a (code=1), thread 1594 (XXXX)</p>
  </blockquote>
  
  <p>Is anyone able to see my error?</p>