uzh-rpg / DSEC

MIT License
131 stars 16 forks source link

Reproducing the Rectification Map #32

Closed AlexanderGaul closed 2 years ago

AlexanderGaul commented 2 years ago

Hello,

I am trying to reproduce the values provided in the rectification map by utilizing the camera calibration parameters.

# xys: pixel coordinates
R = np.array(cams['extrinsics']['R_rect0'])
dist = np.array(cams['intrinsics']['cam0']['distortion_coeffs'])
k_dist = np.array(cams['intrinsics']['cam0']['camera_matrix'])
k_rect = np.array(cams['intrinsics']['camRect0']['camera_matrix'])

K_dist = np.array([[k_dist[0], 0, k_dist[2]],
                   [0, k_dist[1], k_dist[3]],
                   [0, 0, 1]])

xys_K = cv2.undistortPoints(xys, K_dist, dist).reshape(-1, 2)
xys_K = np.concatenate([xys_K, np.ones([len(xys_K), 1])], axis=1)

xys_rect = xys_K.dot(R.transpose())[:, :2] * k_rect[:2] + k_rect[2:4]

Unfortunately, my approach delivers different results. For example, for the corners of the image

[[0, 0],
 [639, 0],
 [0, 479],
 [639, 479]]

I get

[[-13.74142628  -4.9402896 ]
 [654.37295098  -4.84200129]
 [-12.39900617 491.82189056]
 [650.87186114 496.71564016]]

whereas the rectification map supplies

[[-11.992482   -3.8135486]
  [656.11633    -6.081475 ]
  [-10.26636   490.16754  ]
  [652.2097    497.89062  ]]

Is there something I missed?

Ultimately, I would like to transform coordinates from the rectified camera into the distorted camera, i.e. get the inverse of the rectification map.

Thanks!

magehrig commented 2 years ago

Hi @AlexanderGaul

I used the following code for this: https://github.com/uzh-rpg/DSEC/issues/6#issuecomment-822540791

Nonetheless, you mentioned that you actually want to achieve the opposite. For this check out the following comment: https://github.com/uzh-rpg/DSEC/issues/14#issuecomment-841348958

Let me know if this solves your issue.

AlexanderGaul commented 2 years ago

Thank you!