5

The question is how to rotate image using OpenCV and keep original dimensions. Currently using this function:

def rotateImage(image, angle):
   (h, w) = image.shape[:2]
   center = (w / 2, h / 2)
   M = cv2.getRotationMatrix2D(center,angle,1.0)
   rotated_image = cv2.warpAffine(image, M, (w,h))
   return rotated_image

Additionally what kind of algorithm utilised in warpAffine (Bicubic?)

Roman
  • 568
  • 3
  • 8
  • 20
  • maybe you can convert my c++ version to python: http://stackoverflow.com/questions/29944128/opencv-mat-rotation-gets-wrong-result/29945433#29945433 – Micka Jun 09 '15 at 06:12
  • 1
    according to http://docs.opencv.org/modules/imgproc/doc/geometric_transformations.html#warpaffine warpaffine uses CV_INTER_LINEAR (which is linear interpolation) by default. choose INTER_CUBIC for bicubic, INTER_LANCZOS4 or INTER_NEAREST for different methods. – Micka Jun 09 '15 at 06:17
  • You can check [this post](http://stackoverflow.com/questions/22041699/rotate-an-image-without-cropping-in-opencv-in-c) which I found very useful. – Jeru Luke Dec 29 '16 at 10:59

1 Answers1

13

Create new square image with dimension = diagonal of your initial image.
Draw initial image into the center of new image.
Rotate new image

MBo
  • 77,366
  • 5
  • 53
  • 86