37inline Eigen::Vector4d
fetzer_d(
const Eigen::Vector3d& ai,
38 const Eigen::Vector3d& bi,
39 const Eigen::Vector3d& aj,
40 const Eigen::Vector3d& bj,
int u,
int v) {
42 d(0) = ai(u) * aj(v) - ai(v) * aj(u);
43 d(1) = ai(u) * bj(v) - ai(v) * bj(u);
44 d(2) = bi(u) * aj(v) - bi(v) * aj(u);
45 d(3) = bi(u) * bj(v) - bi(v) * bj(u);
57inline std::array<Eigen::Vector4d, 3>
fetzer_ds(
const Eigen::Matrix3d& G) {
58 Eigen::JacobiSVD<Eigen::Matrix3d>
svd(
59 G, Eigen::ComputeFullU | Eigen::ComputeFullV);
60 const Eigen::Vector3d s =
svd.singularValues();
62 const Eigen::Vector3d v_0 =
svd.matrixV().col(0);
63 const Eigen::Vector3d v_1 =
svd.matrixV().col(1);
64 const Eigen::Vector3d u_0 =
svd.matrixU().col(0);
65 const Eigen::Vector3d u_1 =
svd.matrixU().col(1);
67 const Eigen::Vector3d ai(
68 s(0) * s(0) * (v_0(0) * v_0(0) + v_0(1) * v_0(1)),
69 s(0) * s(1) * (v_0(0) * v_1(0) + v_0(1) * v_1(1)),
70 s(1) * s(1) * (v_1(0) * v_1(0) + v_1(1) * v_1(1)));
72 const Eigen::Vector3d aj(u_1(0) * u_1(0) + u_1(1) * u_1(1),
73 -(u_0(0) * u_1(0) + u_0(1) * u_1(1)),
74 u_0(0) * u_0(0) + u_0(1) * u_0(1));
76 const Eigen::Vector3d bi(s(0) * s(0) * v_0(2) * v_0(2),
77 s(0) * s(1) * v_0(2) * v_1(2),
78 s(1) * s(1) * v_1(2) * v_1(2));
80 const Eigen::Vector3d bj(u_1(2) * u_1(2), -(u_0(2) * u_1(2)),
83 std::array<Eigen::Vector4d, 3> ds;
84 ds[0] =
fetzer_d(ai, bi, aj, bj, 1, 0);
85 ds[1] =
fetzer_d(ai, bi, aj, bj, 0, 2);
86 ds[2] =
fetzer_d(ai, bi, aj, bj, 2, 1);
116 Eigen::Vector4d d_01_;
117 Eigen::Vector4d d_12_;
131 : Base(model ? model :
noiseModel::Unit::Create(2), fi_key, fj_key) {
134 Matrix3 Ki = Matrix3::Identity();
138 Matrix3 Kj = Matrix3::Identity();
142 const Matrix3 G = Kj.transpose() * F * Ki;
143 const std::array<Eigen::Vector4d, 3> ds =
fetzer_ds(G);
154 constexpr double kMinFocal = 1e-6;
156 std::abs(fi) < kMinFocal ? std::copysign(kMinFocal, fi) : fi;
158 std::abs(fj) < kMinFocal ? std::copysign(kMinFocal, fj) : fj;
159 const double fi2 = fi0 * fi0;
160 const double fj2 = fj0 * fj0;
162 const Eigen::Vector4d& a = d_01_;
163 const Eigen::Vector4d& b = d_12_;
165 double di = a(0) * fj2 + a(1);
166 double dj = b(0) * fi2 + b(2);
168 constexpr double kMinDenom = 1e-12;
169 if (std::abs(di) < kMinDenom) di = std::copysign(kMinDenom, di);
170 if (std::abs(dj) < kMinDenom) dj = std::copysign(kMinDenom, dj);
172 const double ni = a(2) * fj2 + a(3);
173 const double nj = b(1) * fi2 + b(3);
175 const double K0 = -ni / di;
176 const double K1 = -nj / dj;
178 const double r0 = (fi2 - K0) / fi2;
179 const double r1 = (fj2 - K1) / fj2;
183 (*H1)(0, 0) = 2.0 * (1.0 - r0) / fi0;
184 (*H1)(1, 0) = (2.0 * fi0 / fj2) * (b(1) * dj - b(0) * nj) / (dj * dj);
188 (*H2)(0, 0) = (2.0 * fj0 / fi2) * (a(2) * di - a(0) * ni) / (di * di);
189 (*H2)(1, 0) = 2.0 * (1.0 - r1) / fj0;
192 return Vector{{r0, r1}};
typedef and functions to augment Eigen's MatrixXd
typedef and functions to augment Eigen's VectorXd
Base class for noise model factors with N variables.
Non-linear factor base classes.
Global functions in a separate testing namespace.
Definition chartTesting.h:28
Matrix * OptionalMatrixType
This typedef will be used everywhere boost::optional<Matrix&> reference was used previously.
Definition NonlinearFactor.h:57
Eigen::Vector4d fetzer_d(const Eigen::Vector3d &ai, const Eigen::Vector3d &bi, const Eigen::Vector3d &aj, const Eigen::Vector3d &bj, int u, int v)
Build one 4-vector of bilinear coefficients from two pairs of 3-vectors, picking rows (u,...
Definition SelfCalibrationFactor.h:37
void svd(const Matrix &A, Matrix &U, Vector &S, Matrix &V)
SVD computes economy SVD A=U*S*V'.
Definition Matrix.cpp:557
noiseModel::Base::shared_ptr SharedNoiseModel
Aliases.
Definition NoiseModel.h:846
std::uint64_t Key
Integer nonlinear key type.
Definition types.h:43
std::array< Eigen::Vector4d, 3 > fetzer_ds(const Eigen::Matrix3d &G)
Precompute the Fetzer coefficient vectors from G = K_j^T F K_i.
Definition SelfCalibrationFactor.h:57
All noise models live in the noiseModel namespace.
Definition LossFunctions.cpp:33
NoiseModelFactorT()
Definition NoiseModelFactorN.h:257
SelfCalibrationFactor(Key fi_key, Key fj_key, const Matrix3 &F, const Vector2 &pp_i, const Vector2 &pp_j, const SharedNoiseModel &model=nullptr)
Definition SelfCalibrationFactor.h:129
Vector2 evaluateError(const double &fi, const double &fj, OptionalMatrixType H1=nullptr, OptionalMatrixType H2=nullptr) const override
2-vector essential-matrix deviation; Jacobians are 2x1 each.
Definition SelfCalibrationFactor.h:149