1

I rotated the image from the left to the image on the right using

image = cv2.warpAffine(image, R, dst_size, flags=cv2.INTER_LINEAR)

where dst_size is (547, 363), and I've modified R so that the original image should fit in the new dimensions. I show the image with cv2.imshow('rect post-rotation', img) to show the image on the right. You can see that it appears clipped to a size of (363, 547), even though when I print out the img shape, I get (547, 363, 3).

Why does the shape of the image not reflect the shape of the displayed image?

enter image description here

Rose Perrone
  • 61,572
  • 58
  • 208
  • 243
  • Hi, see the answer here http://stackoverflow.com/questions/22041699/rotate-an-image-without-cropping-in-opencv-in-c/22042434#22042434 – Haris May 24 '14 at 02:03

1 Answers1

1

you need to set the destination size to the rotated size ie:

   cv::Size dst_size(imOrig.size().height,imOrig.size().width);

alternatively you can use transpose and flip for 90 degree rotation:

   cv::Mat imRot90 = imOrig.t();   
   cv::flip(imRot90 ,imRot90 ,1); 

cheers

QED
  • 808
  • 8
  • 11
  • I did set the destination size to be the rotated size. – Rose Perrone May 23 '14 at 22:59
  • 1
    are you sure as the co-ordinates of Size, size(x,y), are the other way around to image(y,x), so it is easy to set it wrong. What happens if you set it the other way around? – QED May 23 '14 at 23:53