0
votes

I am calibrating camera using opencv in built function calibrateCamera.

ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1],None,None)
print("translation vector size",len(tvecs))
print("rotation vector size",len(rvecs))
print("translation \n",tvecs)
print("rotation \n",rvecs)

Output:

translation vector size 8
rotation vector size 8
translation 
 [array([[-2.89545711],
       [ 0.53309405],
       [16.90937607]]), array([[ 2.5887548 ],
       [ 4.28267707],
       [13.76961517]]), array([[-3.3813951 ],
       [ 0.46023276],
       [11.62316805]]), array([[-3.94407341],
       [ 2.24712782],
       [12.75758635]]), array([[-2.46697627],
       [-3.45827811],
       [12.90925656]]), array([[ 2.26913044],
       [-3.25178618],
       [15.65704473]]), array([[-3.65842398],
       [-4.35145288],
       [17.28001749]]), array([[-1.53432042],
       [-4.34836431],
       [14.06280739]])]
rotation 
 [array([[-0.08450996],
       [ 0.35247622],
       [-1.54211812]]), array([[-0.23013064],
       [ 1.02133593],
       [-2.79358726]]), array([[-0.34782976],
       [-0.06411541],
       [-1.20030736]]), array([[-0.27641699],
       [ 0.10465832],
       [-1.56231228]]), array([[-0.47298366],
       [ 0.09331131],
       [-0.22505762]]), array([[0.068391  ],
       [0.44710268],
       [0.10818745]]), array([[-0.09848595],
       [ 0.32272789],
       [ 0.31561383]]), array([[-0.35190574],
       [ 0.24381052],
       [ 0.2106984 ]])]

The obtained translation and rotation vectors are consist of eight 3*1 array objects. I expect translation and rotation vector should be of size 3*3 and 3*1 respectively. Please let me know how these values are relevant with translation and rotation matrix. Also suggest me how can I derive translation and rotation matrices from these obtained vectors.

Thanks !

1

1 Answers

1
votes

The eight sets of arrays are the eight images you feed in.

tvecs and rvecs you get from calibrateCamera() are vectors. If you want the matrix form, you have to use Rodrigues().

3x1 translation vector is the one you want.

3x3 rotation matrix can be obtained by cv2.Rodrigues().

for rvec in rvecs
    R_matrix, _ = cv2.Rodrigues(rvecs)

Also, if you want to concatenate the [R t] matrix, try this:

Rt_matirx = np.concatenate((R_matrix, tvec), axis=1)

See opencv document for more information.