3

Consider the fallowing stereo camera system calibration parameters using matlab stereoCameraCalibrator app.

R1 = stereoParams.CameraParameters1.RotationMatrices(:,:,N);
R2 = stereoParams.CameraParameters2.RotationMatrices(:,:,N);
R12 = stereoParams.RotationOfCamera2;

Were:
R1: rotation from world coordinates (for image N) to camera 1.
R2: rotation from world coordinates (for image N) to camera 2.
R12: rotation from camera 1 coordinates to camera 2. As described on a related SO question

If that is correct, shouldn't R12*R1 == R2 ?

But I'm getting different values, so, what I'm missing here?


Edit

Well, it seams all matrices are transposed. So: R12'*R1' == R2' !
Why they are transposed?

Community
  • 1
  • 1
Pedro77
  • 5,176
  • 7
  • 61
  • 91

1 Answers1

3

The reason why they are transposed is due to the fact that when performing geometric transformations between coordinates, MATLAB uses row vectors to perform the transformation whereas column vectors are traditionally used in practice.

In other words, to transform a coordinate from one point to another, you typically perform:

x' = A*x

A would be the transformation matrix and x is a column vector of coordinates. The output x' would be another column vector of coordinates. MATLAB in fact uses a row vector and so if you want to achieve the same effect in multiplication, you must transpose the matrix A (i.e. A^{T}) and pre-multiply by A instead of post-multiplying:

x' = x*A^{T}

Here x would be a row vector and to ensure that weighted combination of rows and columns is correctly accumulated, you must transpose A to maintain the same calculations. However, the shape of the output x' would be a row vector instead.

This can also be verified by transposing the product of two matrices. Specifically, if x' = A*x, then in order to transform the output into a row vector x'^{T}, we must transpose the matrix-vector product:

x'^{T} = (A*x)^{T} = x^{T}*A^{T}

The last statement is a natural property of transposing the product of two matrices. See point 3 at the Transpose Wikipedia article for more details: https://en.wikipedia.org/wiki/Transpose#Properties

The reason why the transpose is performed ultimately stems back to the way MATLAB handles how numbers are aligned in memory. MATLAB is a column-major based language which means that numbers are populated in a matrix column-wise. Therefore, if you were to populate a matrix one element at a time, this would be done in a column-wise fashion and so the coefficients are populated per column instead of per row as we are normally used to, ultimately leading to what we've concluded above.

Therefore, when you have transposed both R12 and R1, this brings back the representation into a row major setting where these matrices were originally column major for ease of MATLAB use. The row major setting thus allows you to use coordinates that are column vectors to facilitate the transformation. This column vector setting is what we are used to. Therefore, multiplying R12 and R1 after you transpose them both brings you to the correct transformation matrix R2 in the standard row major representation.

rayryeng
  • 102,964
  • 22
  • 184
  • 193
  • Oh, got it, thanks for the detailed explanation. Well, I'll transpose the calibration results, since I'm used to this representation and I think it is confusing to change the multiplication order. Also, the old (but very good) Matlab calibration toolbox (www.vision.caltech.edu/bouguetj/calib_doc) output the matrix correctly. – Pedro77 Jun 07 '16 at 21:07
  • @Pedro77 To be honest, I transpose the matrices too. I'm used to the elements aligned in row-major. That toolbox by Jean-Yves Bouguet is a very nice toolbox. I've used it in the past and the parameter estimation is performed correctly as the code and optimizations performed output the matrices in row-major. Glad I could help! – rayryeng Jun 07 '16 at 21:09
  • Going to extend a litle bit here. Have you compared the results from both (like 3D error)? I have some results from an internship, but I going to check myself. I think the matlab app was done based on the Bouguetj Toolbox right? Also, is there a way I can set the checkerboard size of Y different from X instead of a square as in the Bouguetj toolbox? You know, printers are never good enough. – Pedro77 Jun 08 '16 at 17:12
  • Hi there. I've never compared them both. I've actually never really used this portion of MATLAB's CVST so I actually don't know about the checkerboard size. I do know it's based off of the Bouguet toolbox but that's all I really know. – rayryeng Jun 08 '16 at 17:17