Calibration Library 1.0.0
A C++ library for camera calibration and vision-related geometric transformations
Loading...
Searching...
No Matches
handeyeresidual.h
Go to the documentation of this file.
1
7#pragma once
8
9// eigen
10#include <Eigen/Geometry>
11
12#include "../detail/observationutils.h"
13#include "calib/estimation/linear/handeye.h" // MotionPair
14
15namespace calib {
16
17// ---------- Ceres residual (AX = XB): rotation log + translation eq ----------
18struct AxXbResidual final {
19 Eigen::Matrix3d rot_a_, rot_b_;
20 Eigen::Vector3d tra_a_, tra_b_;
21
22 explicit AxXbResidual(const MotionPair& mp)
23 : rot_a_(mp.rot_a), rot_b_(mp.rot_b), tra_a_(mp.tra_a), tra_b_(mp.tra_b) {}
24
25 template <typename T>
26 bool operator()(const T* const q, const T* const t, T* residuals) const {
27 using Vec3 = Eigen::Matrix<T, 3, 1>;
28 using Mat3 = Eigen::Matrix<T, 3, 3>;
29 // q = [w, x, y, z], t = [tx, ty, tz]
30 const Mat3 rot_x = quat_array_to_rotmat(q);
31 const Mat3 rot_a = rot_a_.cast<T>();
32 const Mat3 rot_b = rot_b_.cast<T>();
33 const Mat3 rot_s = rot_a * rot_x * rot_b.transpose() * rot_x.transpose();
34 Eigen::AngleAxis<T> axisangle(rot_s);
35
36 // trans residual from (rot_a - I) tra_x = rot_x tra_b - tra_a
37 const Vec3 tra_x(t[0], t[1], t[2]);
38 const Vec3 tra_a = tra_a_.cast<T>();
39 const Vec3 tra_b = tra_b_.cast<T>();
40 const Vec3 tra_e = (rot_a - Mat3::Identity()) * tra_x - (rot_x * tra_b - tra_a);
41
42 residuals[0] = axisangle.angle() * axisangle.axis()(0);
43 residuals[1] = axisangle.angle() * axisangle.axis()(1);
44 residuals[2] = axisangle.angle() * axisangle.axis()(2);
45 residuals[3] = tra_e(0);
46 residuals[4] = tra_e(1);
47 residuals[5] = tra_e(2);
48 return true;
49 }
50
51 static auto create(const MotionPair& mp) {
52 return new ceres::AutoDiffCostFunction<AxXbResidual, 6, 4, 3>(new AxXbResidual(mp));
53 }
54};
55
56} // namespace calib
Hand-eye calibration algorithms and utilities.
Linear multi-camera extrinsics initialisation (DLT)
Eigen::Matrix3d Mat3
static Eigen::Matrix< T, 3, 3 > quat_array_to_rotmat(const T *const arr)
Eigen::Vector3d tra_b_
Eigen::Vector3d tra_a_
Eigen::Matrix3d rot_b_
bool operator()(const T *const q, const T *const t, T *residuals) const
AxXbResidual(const MotionPair &mp)
static auto create(const MotionPair &mp)
Eigen::Matrix3d rot_a_
Motion pair structure for hand-eye calibration.
Definition handeye.h:34