0

I really hope this isn't a waste of anyone's time but I've run into a small problem. I am able to construct the transformation matrix using the following:

M = 
s*cos(theta)        -s*sin(theta)       t_x
s*sin(theta)        s*cos(theta)        t_y
0                   0                   1

This works if I give the correct values for theta, s (scale) and tx/ty and then use this matrix as one of the arguments for cv::warpPerspective. The problem lies in that this matrix rotates about the (0,0) pixel whereas I would like it to rotate about the centre pixel (cols/2, rows/2). How can incoporate the centre point rotation into this matrix?

user901898
  • 325
  • 6
  • 19

1 Answers1

1

Two possibilities. The first is to use the function getRotationMatrix2D which takes the center of rotation as an argument, and gives you a 2x3 matrix. Add the third row and you're done.

A second possibility is to construct an additional matrix that translates the picture before and after the rotation:

T = 
1 0 -cols/2
0 1 -rows/2
0 0 1

Multiply your rotation matrix M with this one to get the total transform -TMT (e.g. with function gemm) and apply this one with warpPerspective.

dvhamme
  • 1,442
  • 9
  • 10
  • By -T a simple multiplication with -1 is not meant, only the the last column is negated. – YuZ Jul 17 '17 at 08:01