opencvcomputer-visionprojective-geometry

Conjugate rotation transformation in OpenCV


I am trying to apply a certain rotation to an image, but it doesn't work as expected. The rotation I have is:

[0.109285   0.527975    0.000000    
-0.527975   0.109285    0.000000    
0.000000    0.000000    1.000000]

Which should be a rotation of ~78 degrees around the camera center (or the Z axis if you prefer). To build a homography, as there is no translation component, I use the formula: K * R * K^-1 (infinite homography).

The code I use to transform the image (320x240) is:

cv::warpPerspective(image1, image2, K * R * K.inv(), image1.size());

where K is:

[276.666667 0.000000    160.000000  
0.000000    276.666667  120.000000  
0.000000    0.000000    1.000000]

The resulting matrix from K * R * K.inv() is:

[0.109285   0.527975    79.157461   
-0.527975   0.109285    191.361865  
0.000000    0.000000    1.000000]

The result should just be a rotation of the image, but the image gets "zoomed out" like this:

enter image description here

What am I doing wrong?


Solution

  • Apparently my rotation matrix was wrong.