9

I am trying to get a 3x4 camera matrix for triangulation process but calibrateCamera() returns only 3x3 and 4x1 matrices.

How can i get the 3x4 out of those matrices?

Thanks in advance!!

Ander Biguri
  • 35,140
  • 11
  • 74
  • 120
Srol
  • 721
  • 2
  • 7
  • 16

2 Answers2

12

calibrateCamera() returns you
a 3x3 matrix as cameraMatrix,
a 4x1 matrix as distCoeffs, and rvecs and tvecs that are vectors of 3x1 rotation(R) and 3x1 transformation(t) matrices.

What you want is ProjectionMatrix, which is multiply [cameraMatrix] by [R|t]. 3D into 2D Projection

Therefore, it returs you a 3x4 ProjectionMatrix.
You can read OpenCV documentation for more info.

Zhr Saghaie
  • 1,031
  • 2
  • 16
  • 41
  • You say we have 3x1 rotation, but in the formula below it is 3x3 (r_11, ..., r_33). How is that possible? Can you add some c++ code for calculating the projection matrix from camMatrix (3x3) and distMatrix (4x1)? – Dennis Jan 10 '16 at 19:11
  • that's correct, Rodriguez convert the rotation vector to rotation matrix which you can use in the above formula – Thesane Feb 08 '16 at 15:31
2

If you are using cameraCalibrate(), you must be getting mtx, rvecs and tvecs. R is 3x1 which you need to convert to 3x3 using Rodrigues method of opencv. So the final code will look something like:

R = cv2.Rodrigues(rvecs[0])[0]
t = tvecs[0]
Rt = np.concatenate([R,t], axis=-1) # [R|t]
P = np.matmul(mtx,Rt) # A[R|t]

assuming you have used multiple images for calibrating camera, here I am using only the first one to get P matrix for first image. For any other image you can use rvecs[IMAGE_NUMBER], tvecs[IMAGE_NUMBER] for the corresponding P matrix

Salman Shah
  • 3
  • 1
  • 2
sam
  • 2,263
  • 22
  • 34