34 template<
class CAMERA>
35 class CameraSet :
public std::vector<CAMERA, Eigen::aligned_allocator<CAMERA> > {
43 typedef typename CAMERA::Measurement
Z;
44 typedef typename CAMERA::MeasurementVector ZVector;
51 const ZVector& measured) {
54 size_t m = predicted.size();
55 if (measured.size() != m)
56 throw std::runtime_error(
"CameraSet::errors: size mismatch");
60 for (
size_t i = 0,
row = 0; i < m; i++,
row +=
ZDim) {
62 if(
ZDim==3 && std::isnan(bi(1))){
73 typedef Eigen::Matrix<double, ZDim, D>
MatrixZD;
74 typedef std::vector<MatrixZD, Eigen::aligned_allocator<MatrixZD> > FBlocks;
81 virtual void print(
const std::string& s =
"")
const {
82 std::cout << s <<
"CameraSet, cameras = \n";
83 for (
size_t k = 0; k < this->size(); ++k)
89 if (this->size() != p.size())
91 bool camerasAreEqual =
true;
92 for (
size_t i = 0; i < this->size(); i++) {
93 if (this->at(i).equals(p.at(i), tol) ==
false)
94 camerasAreEqual =
false;
97 return camerasAreEqual;
106 template<
class POINT>
108 boost::optional<FBlocks&> Fs = boost::none,
109 boost::optional<Matrix&> E = boost::none)
const {
114 size_t m = this->size();
119 if (E) E->resize(
ZDim * m, N);
120 if (Fs) Fs->resize(m);
123 for (
size_t i = 0; i < m; i++) {
125 Eigen::Matrix<double, ZDim, N> Ei;
126 z.emplace_back(this->at(i).
project2(point, Fs ? &Fi : 0, E ? &Ei : 0));
127 if (Fs) (*Fs)[i] = Fi;
128 if (E) E->block<
ZDim, N>(
ZDim * i, 0) = Ei;
135 template<
class POINT>
137 boost::optional<FBlocks&> Fs = boost::none,
138 boost::optional<Matrix&> E = boost::none)
const {
150 const Matrix& E,
const Eigen::Matrix<double, N, N>& P,
const Vector& b) {
153 size_t m = Fs.size();
156 size_t M1 =
D * m + 1;
157 std::vector<DenseIndex> dims(m + 1);
158 std::fill(dims.begin(), dims.end() - 1,
D);
163 for (
size_t i = 0; i < m; i++) {
166 const auto FiT = Fi.transpose();
167 const Eigen::Matrix<double, ZDim, N> Ei_P =
172 - FiT * (Ei_P * (E.transpose() * b)));
176 * (Fi - Ei_P * E.block(
ZDim * i, 0,
ZDim, N).transpose() * Fi));
179 for (
size_t j = i + 1; j < m; j++) {
184 * (Ei_P * E.block(
ZDim * j, 0,
ZDim, N).transpose() * Fj));
189 return augmentedHessian;
195 const Matrix& E,
double lambda,
bool diagonalDamping =
false) {
197 Matrix EtE = E.transpose() * E;
199 if (diagonalDamping) {
200 EtE.diagonal() += lambda * EtE.diagonal();
203 EtE += lambda * Eigen::MatrixXd::Identity(n, n);
210 static Matrix
PointCov(
const Matrix& E,
const double lambda = 0.0,
211 bool diagonalDamping =
false) {
214 ComputePointCovariance<2>(P2, E, lambda, diagonalDamping);
218 ComputePointCovariance<3>(P3, E, lambda, diagonalDamping);
228 const Matrix& E,
const Vector& b,
const double lambda = 0.0,
229 bool diagonalDamping =
false) {
232 ComputePointCovariance<2>(P, E, lambda, diagonalDamping);
233 return SchurComplement<2>(Fblocks, E, P, b);
236 ComputePointCovariance<3>(P, E, lambda, diagonalDamping);
237 return SchurComplement<3>(Fblocks, E, P, b);
247 const Eigen::Matrix<double, N, N>& P,
const Vector& b,
251 assert(keys.size()==Fs.size());
252 assert(keys.size()<=allKeys.size());
255 for (
size_t slot = 0; slot < allKeys.size(); slot++)
256 KeySlotMap.insert(std::make_pair(allKeys[slot], slot));
263 size_t m = Fs.size();
264 size_t M = (augmentedHessian.
rows() - 1) /
D;
265 assert(allKeys.size()==M);
268 for (
size_t i = 0; i < m; i++) {
271 const auto FiT = Fi.transpose();
272 const Eigen::Matrix<double, 2, N> Ei_P = E.template block<ZDim, N>(
286 - FiT * (Ei_P * (E.transpose() * b)));
292 ((FiT * (Fi - Ei_P * E.template block<ZDim, N>(
ZDim * i, 0).transpose() * Fi))).eval());
295 for (
size_t j = i + 1; j < m; j++) {
305 -FiT * (Ei_P * E.template block<ZDim, N>(
ZDim * j, 0).transpose() * Fj));
316 template<
class ARCHIVE>
317 void serialize(ARCHIVE & ar,
const unsigned int ) {
322 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
325 template<
class CAMERA>
328 template<
class CAMERA>
331 template<
class CAMERA>
335 template<
class CAMERA>
Eigen::Matrix< double, ZDim, D > MatrixZD
Definitions for blocks of F.
Definition: CameraSet.h:73
ptrdiff_t DenseIndex
The index type for Eigen objects.
Definition: types.h:63
A set of cameras, all with their own calibration.
Definition: CameraSet.h:35
static Vector ErrorVector(const ZVector &predicted, const ZVector &measured)
Make a vector of re-projection errors.
Definition: CameraSet.h:50
static const int ZDim
Measurement dimension.
Definition: CameraSet.h:47
DenseIndex rows() const
Row size.
Definition: SymmetricBlockMatrix.h:119
bool equals(const CameraSet &p, double tol=1e-9) const
equals
Definition: CameraSet.h:88
CAMERA::Measurement Z
2D measurement and noise model for each of the m views The order is kept the same as the keys that we...
Definition: CameraSet.h:43
A helper that implements the traits interface for GTSAM types.
Definition: Testable.h:150
void setOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
Set an off-diagonal block. Only the upper triangular portion of xpr is evaluated.
Definition: SymmetricBlockMatrix.h:206
virtual void print(const std::string &s="") const
print
Definition: CameraSet.h:81
ZVector project2(const POINT &point, boost::optional< FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
Project a point (possibly Unit3 at infinity), with derivatives Note that F is a sparse block-diagonal...
Definition: CameraSet.h:107
void setDiagonalBlock(DenseIndex I, const XprType &xpr)
Set a diagonal block. Only the upper triangular portion of xpr is evaluated.
Definition: SymmetricBlockMatrix.h:200
Give fixed size dimension of a type, fails at compile time if dynamic.
Definition: Manifold.h:164
A thin wrapper around std::map that uses boost's fast_pool_allocator.
Calibrated camera for which only pose is unknown.
Access to matrices via blocks of pre-defined sizes.
FastVector< Key > KeyVector
Define collection type once and for all - also used in wrappers.
Definition: Key.h:56
static void ComputePointCovariance(Eigen::Matrix< double, N, N > &P, const Matrix &E, double lambda, bool diagonalDamping=false)
Computes Point Covariance P, with lambda parameter.
Definition: CameraSet.h:194
A manifold defines a space in which there is a notion of a linear tangent space that can be centered ...
Definition: concepts.h:30
Eigen::SelfAdjointView< Block, Eigen::Upper > diagonalBlock(DenseIndex J)
Return the J'th diagonal block as a self adjoint view.
Definition: SymmetricBlockMatrix.h:140
static Matrix PointCov(const Matrix &E, const double lambda=0.0, bool diagonalDamping=false)
Computes Point Covariance P, with lambda parameter, dynamic version.
Definition: CameraSet.h:210
static void UpdateSchurComplement(const FBlocks &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b, const KeyVector &allKeys, const KeyVector &keys, SymmetricBlockMatrix &augmentedHessian)
Applies Schur complement (exploiting block structure) to get a smart factor on cameras,...
Definition: CameraSet.h:246
static SymmetricBlockMatrix SchurComplement(const FBlocks &Fs, const Matrix &E, const Eigen::Matrix< double, N, N > &P, const Vector &b)
Do Schur complement, given Jacobian as Fs,E,P, return SymmetricBlockMatrix G = F' * F - F' * E * P * ...
Definition: CameraSet.h:149
static const int D
Camera dimension.
Definition: CameraSet.h:46
Definition: SymmetricBlockMatrix.h:51
Global functions in a separate testing namespace.
Definition: chartTesting.h:28
Concept check for values that can be used in unit tests.
void updateOffDiagonalBlock(DenseIndex I, DenseIndex J, const XprType &xpr)
Update an off diagonal block.
Definition: SymmetricBlockMatrix.h:233
const MATRIX::ConstRowXpr row(const MATRIX &A, size_t j)
Extracts a row view from a matrix that avoids a copy.
Definition: Matrix.h:224
void updateDiagonalBlock(DenseIndex I, const XprType &xpr)
Increment the diagonal block by the values in xpr. Only reads the upper triangular part of xpr.
Definition: SymmetricBlockMatrix.h:217
static SymmetricBlockMatrix SchurComplement(const FBlocks &Fblocks, const Matrix &E, const Vector &b, const double lambda=0.0, bool diagonalDamping=false)
Do Schur complement, given Jacobian as Fs,E,P, return SymmetricBlockMatrix Dynamic version.
Definition: CameraSet.h:227
Vector reprojectionError(const POINT &point, const ZVector &measured, boost::optional< FBlocks & > Fs=boost::none, boost::optional< Matrix & > E=boost::none) const
Calculate vector [project2(point)-z] of re-projection errors.
Definition: CameraSet.h:136
friend class boost::serialization::access
Serialization function.
Definition: CameraSet.h:315