Ask Your Question
0

getRotationMatrix2D gives error

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

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 -0600

berak gravatar image

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

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 -0600 )edit

I'm sorry, it worked. Thanks!!

zshn25 gravatar imagezshn25 ( 2016-02-26 04:14:49 -0600 )edit

Question Tools

1 follower

Stats

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

Seen: 4,254 times

Last updated: Feb 26 '16