MCPcopy Create free account
hub / github.com/ComputationalRobotics/XM-code / ATE_LEASTSQUARE

Function ATE_LEASTSQUARE

utils/error.py:213–249  ·  view source on GitHub ↗
(R_est,t_est,R_gt,t_gt)

Source from the content-addressed store, hash-verified

211
212
213def ATE_LEASTSQUARE(R_est,t_est,R_gt,t_gt):
214 # R_est: 3x3N
215 # t_est: 3xN
216 # R_gt: 3x3N
217 # t_gt: 3xN
218 # return: ATE
219 N = int(R_est.shape[1]/3)
220 assert R_est.shape == R_gt.shape
221 assert t_est.shape == t_gt.shape
222 assert N == t_est.shape[1]
223
224 # find global transformation
225 # find transformation
226 rotations_target = [R_gt[:, 3 * i:3 * (i + 1)] @ R_est[:, 3 * i:3 * (i + 1)].T for i in range(N)]
227 R = average_rotation_from_3x3n(rotations_target)
228 rotation_error = [np.linalg.norm(R @ R_est[:, 3 * i:3 * (i + 1)] - R_gt[:, 3 * i:3 * (i + 1)]) for i in range(N)]
229 print('rotation error:',np.mean(rotation_error))
230
231 target = R @ t_est
232 target_avg = np.mean(target, axis=1)
233 target = target - target_avg.reshape(3, 1)
234
235
236 # find scale
237 t_gt_avg = np.mean(t_gt, axis=1)
238 cov_t_gt = np.mean(np.linalg.norm(t_gt - t_gt_avg.reshape(3, 1), axis=0))
239 cov_t_est = np.mean(np.linalg.norm(target, axis=0))
240 s = cov_t_gt / cov_t_est
241
242 target = s * target
243
244 # find translation
245 t = t_gt - target
246 t_avg = np.mean(t, axis=1)
247
248 # (R * t_est - target_avg) * s + t_avg
249 return s, R, t_avg.reshape(3, 1) - target_avg.reshape(3 , 1) * s
250
251if __name__ == "__main__":
252 N = 5

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected