title: OpenCV Android Combine Mats
body: <p>I am using OpenCV in Android app, i have some problems with combining Mats within onCameraFrame.</p>
  <ul>
  <li>onCameraFrame generates image from camera with a certain size e.g. 800x560.</li>
  <li>I do some manipulation on image which is cut from original image (it's e.g. 512x512)</li>
  <li>API requires to return image in the same size as original image so i need to resize my newly generated image. I would like to not stretch but add black bars around it so that it stays the same.</li>
  </ul>
  <pre><code>      @Override
          public Mat onCameraFrame(CameraBridgeViewBase.CvCameraViewFrame inputFrame) {
      //        Log.i(TAG, &quot;onCameraFrame: &quot; + inputFrame.rgba().size());
              dft = new DFT();
              frame = inputFrame.rgba();
      
              int cropWidth = 512;
              int cropHeight = 512;
              int cropCenterX = (int)((frame.width()-cropWidth)/2.0);
              int cropCenterY = (int)((frame.height()-cropHeight)/2.0);
              Rect rectCrop = new Rect(cropCenterX, cropCenterY, cropWidth, cropHeight);
              Mat croppedImage = new Mat(frame, rectCrop);
                      resize(croppedImage,             
                      croppedImage,           
                      frame.size(),     
                      0,
                      0,
                      INTER_CUBIC       
              );
              return croppedImage;
          }
  </code></pre>
  <p>My idea after some research was as follows:</p>
  <pre><code>Mat output = new Mat(frame.size(),frame.type());
          croppedImage.copyTo(output.submat(new Rect(0,0,croppedImage.rows(),croppedImage.cols())));
  </code></pre>
  <p>which surprisingly did not crash the app but was not working properly. Some crazy glittery effect.</p>
  <p>Am i doing something wrong here?</p>
  <p>Grateful for any ideas :)</p>