Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rotate image without cropping OpenCV

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?)

like image 706
Roman Avatar asked Jun 08 '15 22:06

Roman


1 Answers

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

like image 90
MBo Avatar answered Oct 21 '22 01:10

MBo