title: OpenCV for Android: Simple example to convert Image to Greyscale
body: <p>As a starter I just want to convert an Bitmap to greyscale via OpenCV. I have everything
  running, but it crashes hard as soon as i want to convert the image to greyscale. 
  Can anyone help out? I hope the snippets are enough, if not i can attach the rest.</p>
  
  <p>part of the java file:</p>
  
  <pre><code>                // convert to opencv structure
                  Mat image = new Mat();
                  Mat grayimage = new Mat();
                  Utils.bitmapToMat(b2, image);
  
                  // call opencv for processing
                  grayimage = convertToGray (image);
  
                  // convert back
                  Utils.matToBitmap(grayimage, b2);
  </code></pre>
  
  <p>JNI cpp file:</p>
  
  <pre><code>JNIEXPORT jlong JNICALL Java_com_my_sample_MainMenuActivity_convertToGray (JNIEnv*, jobject, jlong addrRGBA)
  {
      LOGI("Converting to Gray.");
      Mat *mRGBA  = (Mat*)addrRGBA;
  
      Mat *_retval_;
      cvtColor(*mRGBA, *_retval_, CV_RGB2GRAY);
  
      LOGI("Successfully finished Converting to Gray.");
      return (jlong) _retval_;
  }
  </code></pre>
  
  <p>It never gets to it logging successful having converted the image.
  Seems as if the Bitmap was not properly converted to a Mat.
  The Bitmap itself does exist, I can show it on a ImageView.
  Anyone a clue what I'm (obviously) doing wrong?</p>
  
  <pre><code>05-14 21:26:27.082: I/native(22394): Converting to Gray.
  05-14 21:26:27.082: A/libc(22394): Fatal signal 11 (SIGSEGV) at 0xcd10001d (code=1), thread 22394 (ialabs.mysample)
  </code></pre>
  
  <p>Sorry if this question is answered elsewhere, i haven't found an example with Mat, 
  just some with IplImage, it seems.</p>