title: Issue with image rotation using JavaCV library
body: <p>I am writing an Android application which records video for a specified amount of time. Everything works fine if I record using the smartphone's back camera. The app has a feature to pause/record feature like in Vine app. The issue comes when recording using the device's front camera. The video surface frame looks fine when storing/playing the video the video is upside down. There is a lot of things discussed about this issue everywhere. But I didn't find any solution that WORKS. </p>
  
  <p>Have a look at the code and image mentioned below. </p>
  
  <p>Here is the original image taken from front camera. I have turned it upside down for a better view.</p>
  
  <p><img src="https://i.stack.imgur.com/Hhh0l.png" alt="enter image description here"></p>
  
  <p>Here is what I actually get after rotation:</p>
  
  <p><img src="https://i.stack.imgur.com/tD33Y.png" alt="enter image description here"></p>
  
  <p>Method:</p>
  
  <pre><code>     IplImage copy = cvCloneImage(image);
       IplImage rotatedImage = cvCreateImage(cvGetSize(copy), copy.depth(), copy.nChannels());
       //Define Rotational Matrix
       CvMat mapMatrix = cvCreateMat(2, 3, CV_32FC1);
  
       //Define Mid Point
       CvPoint2D32f centerPoint = new CvPoint2D32f();
       centerPoint.x(copy.width() / 2);
       centerPoint.y(copy.height() / 2);
  
       //Get Rotational Matrix
       cv2DRotationMatrix(centerPoint, angle, 1.0, mapMatrix);
  
       //Rotate the Image
       cvWarpAffine(copy, rotatedImage, mapMatrix, CV_INTER_CUBIC + CV_WARP_FILL_OUTLIERS, cvScalarAll(170));
       cvReleaseImage(copy);
       cvReleaseMat(mapMatrix);
  </code></pre>
  
  <p>I have tried doing </p>
  
  <pre><code>     double angleTemp = angle;
  
       angleTemp= ((angleTemp / 90)%4)*90;       
       final int number = (int) Math.abs(angleTemp/90);
  
       for(int i = 0; i != number; ++i){            
           cvTranspose(rotatedImage, rotatedImage);
           cvFlip(rotatedImage, rotatedImage, 0);           
       }
  </code></pre>
  
  <p>Ends up in throwing exception saying that source and destination doesn't match with number of columns and rows.</p>
  
  <p><strong>Update:</strong></p>
  
  <p>Video is recorded in this way.</p>
  
  <pre><code>IplImage newImage = null;
  if(cameraSelection == CameraInfo.CAMERA_FACING_FRONT){
      newImage = videoRecorder.rotate(yuvIplImage, 180);
      videoRecorder.record(newImage);
  }
  else
      videoRecorder.record(yuvIplImage);  
  </code></pre>
  
  <p>Rotation is done in this way:</p>
  
  <pre><code>    IplImage img = IplImage.create(image.height(), image.width(),
              image.depth(), image.nChannels());
  
      for (int i = 0; i &lt; 180; i++) {
          cvTranspose(image, img);
          cvFlip(img, img, 0);
      }
  </code></pre>
  
  <p>Can anyone point out what is wrong here if you have experienced this before?</p>