rotation angle of the perspective matrix

China☆狼群 提交于 2021-02-10 15:49:21

问题


How can I detect the rotation angle from a perspective matrix?

I wrote this code ,but the resulted angle doesn't exceed 40 ...

Mat mmat;
mmat.create(3,3,CV_32FC1);
mmat=getPerspectiveTransform(templPoints,imgPoints);
cout<< mmat<<endl<<endl;
float angle=acos(mmat.at<double>(0,0));
angle=(angle*180)/3.14;
cout<<"angle is"<<angle<<endl;

回答1:


getPerspectiveTransform returns an homography matrix which can be decomposed like this:

[R11,R12,T1]

[R21,R22,T2]

[ P , P , 1]

R represents a rotation matrix, T represents a translation, and P represents a perspective warp.

More info on what rotation matrix represents:

http://en.wikipedia.org/wiki/Rotation_matrix

http://mathworld.wolfram.com/RotationMatrix.html




回答2:


The process is as follows. Consider a 3D point X, represented in homogeneous coordinates by a column vector [ x1, x2, x3, 1]' (where I use the prime symbol "'" to indicate transposition). Consider then a 2D point u = [u1, u2, 1]' that is the image of X in the (perspective) camera. Then the camera's projection is represented by a 3x4 projection matrix P such that

u = P * X .

where "*" means row-by-column product: u1 = P11*x1 + P12*x2 + P13*x3 + P14, etc.

Matrix P can be decomposed in the product of two matrices:

P = K * Q

where K is a 3x3 upper-diagonal matrix

K = [ fx s  cx
      0  fy cy
      0  0  1 ]

that represents the camera, and Q is a 3x4 matrix

Q = [R | t]

where R is the 3x3 rotation matrix of the camera, and t is the 3x1 translation vector.

If you are given the project matrix P, the procedure for recovering the K, R and t is as follows:

  1. Compute the "RQ decomposition" of P
  2. Extract R from Q (just read its leftmost 3 columns)


来源:https://stackoverflow.com/questions/10969170/rotation-angle-of-the-perspective-matrix

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!