'Properly rotate image in OpenCV?

I have the following method for rotating images (python):

> def rotateImage(image, angle):
>     row,col = image.shape[0:2]
>     center=tuple(np.array([row,col])/2)
>     rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
>     new_image = cv2.warpAffine(image, rot_mat, (col,row))
>     return new_image

This is the original picture: Original

This is the rotated (15 degree angle) picture that OpenCV returns: Rotated by CV2 This is the image if I rotate the image around the center in photoshop: Rotated by PS

This are the two roated images superimposed: enter image description here

Obviously there is a difference. I'm pretty sure Photoshop did it correctly (or better - I did it correctly in photoshop), what am I missing?



Solution 1:[1]

As pointed out in the comments, the X and Y coordinates of your center are swapped. The first parameter of cv2.getRotationMatrix2D is a point, where X is first and Y is second.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 rikyeah