title: Cropping an image using openCV Matrix using Android binaries
body: <p>I'm running into problems cropping an image using the Android OpenCV binaries. </p>
  
  <p>This is what I'm doing to try to crop the upper left quadrant of the image:</p>
  
  <pre><code>Initialization {
      mYuv = new Mat(mFrameSize.height + mFrameSize.height / 2, mFrameSize.width, CvType.CV_8UC1);
      mGraySubmat = mYuv.submat(0, mFrameSize.height, 0, mFrameSize.width);
  }
  
  
  processFrame(byte[] data) {
     mYuv.put(0, 0, data);
     Imgproc.cvtColor(mGraySubmat, mRgba, Imgproc.COLOR_GRAY2BGR, 4);
     bmp = Bitmap.createBitmap(mFrameSize.width/2, mFrameSize.height/2, Bitmap.Config.ARGB_8888);
     Rect roi = new Rect(0,0,mFrameSize.width/2,mFrameSize.height/2);
     Mat faceMat = new Mat(mRgba,roi);
     Utils.matToBitmap(faceMat.clone(), bmp);       
  </code></pre>
  
  <p>}</p>
  
  <p>What I get is a garbled image. I've seen other posts that say to do what I'm doing but it's not working. Actually the image looks like it's there but there are also shadow images that are out of proportion.</p>
  
  <p>I can do this manually and it works file - see below. Am I doing something wrong?</p>
  
  <pre><code>processFrame(byte[] data) {
  
       for (int i = 0; i &lt; frameSize; i++) {
       int y = (0xff &amp; ((int) data[i]));
       rgba[i] = 0xff000000 + (y &lt;&lt; 16) + (y &lt;&lt; 8) + y;
  }
  // Example of cropping the upper left corder
  bmp = Bitmap.createBitmap(mFrameSize.width/2, mFrameSize.height/2, Bitmap.Config.RGB_565);
  bmp.setPixels(rgba, 0/* offset */, mFrameSize.width /* stride */, 0, 0, mFrameSize.width/2, mFrameSize.height/2);
  </code></pre>