Ask Your Question
0

getRotationMatrix2D gives error

asked 2016-02-26 00:15:07 -0500

zshn25 gravatar image

The python function getRotationMatrix2D as follows

center = tuple(np.array(image.shape)/2)
rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
result = cv2.warpAffine(image, rot_mat, image.shape,flags=cv2.INTER_LINEAR)

gives this error

Traceback (most recent call last):
File "C:\Users\zeeshan khan\Desktop\opencv\Code\Python\rotate.py", line 13, in <module>
rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
TypeError: function takes exactly 2 arguments (3 given)
edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-02-26 03:07:38 -0500

berak gravatar image

updated 2016-02-26 03:08:26 -0500

np.shape() returns a 3d array, while cv2.getRotationMatrix2D() expects a 2d tuple for the center point.

you have to shave off the 3rd dimension (depth), to make it work:

center = tuple(np.array(image.shape)[:2]/2) # 2d !
rot_mat = cv2.getRotationMatrix2D(center,angle,1.0)
result = cv2.warpAffine(image, rot_mat, image.shape,flags=cv2.INTER_LINEAR)
edit flag offensive delete link more

Comments

(admittedly, a very confusing error..)

berak gravatar imageberak ( 2016-02-26 03:30:12 -0500 )edit

I'm sorry, it worked. Thanks!!

zshn25 gravatar imagezshn25 ( 2016-02-26 04:14:49 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2016-02-26 00:15:07 -0500

Seen: 1,879 times

Last updated: Feb 26 '16