31 #include <boost/assign/std/vector.hpp> 32 #include <boost/shared_ptr.hpp> 40 using namespace gtsam;
55 push_back(boost::make_shared<Projection>(z, model,
X(i),
L(j)));
74 double U1 = rand() / (double) (RAND_MAX);
75 double U2 = rand() / (double) (RAND_MAX);
78 S = V1 * V1 + V2 * V2;
80 return sqrt(-2.
f * (
double)
log(S) / S) * V1;
89 vector<Point3> landmarks;
90 landmarks.push_back(
Point3(-1., -1., z));
91 landmarks.push_back(
Point3(-1., 1., z));
92 landmarks.push_back(
Point3(1., 1., z));
93 landmarks.push_back(
Point3(1., -1., z));
94 landmarks.push_back(
Point3(-1.5, -1.5, 1.5 * z));
95 landmarks.push_back(
Point3(-1.5, 1.5, 1.5 * z));
96 landmarks.push_back(
Point3(1.5, 1.5, 1.5 * z));
97 landmarks.push_back(
Point3(1.5, -1.5, 1.5 * z));
98 landmarks.push_back(
Point3(-2., -2., 2 * z));
99 landmarks.push_back(
Point3(-2., 2., 2 * z));
100 landmarks.push_back(
Point3(2., 2., 2 * z));
101 landmarks.push_back(
Point3(2., -2., 2 * z));
106 vector<GeneralCamera>
X;
113 const Cal3_S2 K(640, 480, 0.1, 320, 240);
114 vector<GeneralCamera>
X;
121 const vector<GeneralCamera>& cameras,
const vector<Point3>& landmarks) {
123 for (
size_t i = 0;
i < landmarks.size(); ++
i)
124 ordering->push_back(
L(
i));
125 for (
size_t i = 0;
i < cameras.size(); ++
i)
126 ordering->push_back(
X(
i));
134 const Symbol cameraFrameNumber(
'x', 1), landmarkNumber(
'l', 1);
136 boost::shared_ptr<Projection>
factor1(
137 new Projection(z, sigma, cameraFrameNumber, landmarkNumber));
139 boost::shared_ptr<Projection>
factor2(
140 new Projection(z, sigma, cameraFrameNumber, landmarkNumber));
171 for (
size_t j = 0;
j < cameras.size(); ++
j) {
172 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
178 const size_t nMeasurements = cameras.size() * landmarks.size();
181 const double noise =
baseline * 0.1;
183 for (
size_t i = 0;
i < cameras.size(); ++
i)
186 for (
size_t i = 0; i < landmarks.size(); ++
i) {
208 for (
size_t j = 0;
j < cameras.size(); ++
j) {
209 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
215 const size_t nMeasurements = cameras.size() * landmarks.size();
218 const double noise =
baseline * 0.1;
220 for (
size_t i = 0;
i < cameras.size(); ++
i)
224 for (
size_t i = 0; i < landmarks.size(); ++
i) {
231 values.
insert(
L(i), landmarks[i]);
236 const double reproj_error = 1
e-5;
241 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
251 const double noise =
baseline * 0.1;
253 for (
size_t i = 0;
i < cameras.size(); ++
i) {
254 for (
size_t j = 0;
j < landmarks.size(); ++
j) {
255 Point2 z = cameras[
i].project(landmarks[
j]);
260 const size_t nMeasurements = landmarks.size() * cameras.size();
263 for (
size_t i = 0;
i < cameras.size(); ++
i)
266 for (
size_t j = 0;
j < landmarks.size(); ++
j) {
273 for (
size_t i = 0; i < cameras.size(); ++
i)
276 const double reproj_error = 1
e-5;
281 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
292 for (
size_t j = 0;
j < cameras.size(); ++
j) {
293 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
299 const size_t nMeasurements = landmarks.size() * cameras.size();
302 for (
size_t i = 0;
i < cameras.size(); ++
i) {
303 const double rot_noise = 1
e-5, trans_noise = 1
e-3, focal_noise = 1,
310 trans_noise, trans_noise, trans_noise,
311 focal_noise, focal_noise,
313 trans_noise, trans_noise
315 values.
insert(
X(
i), cameras[
i].retract(delta));
319 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
325 for (
size_t i = 0;
i < landmarks.size(); ++
i)
328 const double reproj_error = 1
e-5;
333 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
343 for (
size_t j = 0;
j < cameras.size(); ++
j) {
344 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
350 const size_t nMeasurements = cameras.size() * landmarks.size();
353 const double noise =
baseline * 0.1;
355 for (
size_t i = 0;
i < cameras.size(); ++
i)
359 for (
size_t i = 0; i < landmarks.size(); ++
i) {
372 noiseModel::Isotropic::Sigma(1, 10.));
374 const double reproj_error = 1
e-5;
379 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
389 noiseModel::Isotropic::Sigma(1, 1.));
391 noiseModel::Isotropic::Sigma(6, 1.));
415 noiseModel::Isotropic::Sigma(6, 1.));
418 noiseModel::Isotropic::Sigma(1, 1.));
420 noiseModel::Isotropic::Sigma(6, 1.));
453 vector<SharedNoiseModel> models;
456 using namespace noiseModel;
457 Rot2 R = Rot2::fromAngle(0.3);
460 Isotropic::Sigma(2, 0.5), Constrained::All(2), Gaussian::Covariance(cov);
469 factor.NoiseModelFactor::linearize(values);
476 HessianFactor expectedHessian(*expected), actualHessian(*actual);
506 for (
size_t i = 0;
i < cameras.size(); ++
i)
508 for (
size_t j = 0;
j < landmarks.size(); ++
j)
511 for (
size_t i = 0; i < cameras.size(); ++
i) {
512 for (
size_t j = 0; j < landmarks.size(); ++
j) {
513 Point2 z = cameras[
i].project(landmarks[j]);
515 boost::make_shared<Projection>(
z,
sigma1,
X(i),
L(j));
NonlinearEquality< Point3 > Point3Constraint
boost::shared_ptr< GaussianFactor > linearize(const Values &values) const override
Linearize using fixed-size matrices.
NonlinearEquality< GeneralCamera > CameraConstraint
virtual const Values & optimize()
Concept check for values that can be used in unit tests.
static int runAllTests(TestResult &result)
Factor Graph consisting of non-linear factors.
noiseModel::Diagonal::shared_ptr model
void insert(Key j, const Value &val)
static enum @843 ordering
static const double sigma
Rot2 R(Rot2::fromAngle(0.1))
EIGEN_DEVICE_FUNC const LogReturnType log() const
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
static vector< Point3 > genPoint3()
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
boost::shared_ptr< This > shared_ptr
static boost::shared_ptr< Ordering > getOrdering(const vector< GeneralCamera > &cameras, const vector< Point3 > &landmarks)
static const SharedNoiseModel sigma1(noiseModel::Unit::Create(2))
static const Point3 pt(1.0, 2.0, 3.0)
NonlinearFactorGraph graph
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
void addPrior(Key key, const T &prior, const SharedNoiseModel &model=nullptr)
double relativeErrorTol
The maximum relative error decrease to stop iterating (default 1e-5)
Base class for all pinhole cameras.
TEST(GeneralSFMFactor, equals)
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&...args)
Emplace a shared pointer to factor of given type.
void addPoint3Constraint(int j, const Point3 &p)
#define EXPECT(condition)
GeneralSFMFactor< GeneralCamera, Point3 > Projection
Point2(* f)(const Point3 &, OptionalJacobian< 2, 3 >)
A nonlinear optimizer that uses the Levenberg-Marquardt trust-region scheme.
Array< double, 1, 3 > e(1./3., 0.5, 2.)
static SmartStereoProjectionParams params
double error() const
return error in current optimizer state
boost::shared_ptr< This > shared_ptr
shared_ptr to this class
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
static const double baseline
void addMeasurement(int i, int j, const Point2 &z, const SharedNoiseModel &model)
Matrix augmentedInformation() const override
void addCameraConstraint(int j, const GeneralCamera &p)
static vector< GeneralCamera > genCameraVariableCalibration()
detail::initimpl::constructor< Args... > init()
Binds an existing constructor taking arguments Args...
A Gaussian factor using the canonical parameters (information form)
JacobianFactor factor2(keyX, A21, keyY, A22, b2, noiseModel::Isotropic::Sigma(2, sigma2))
static double getGaussian()
static vector< GeneralCamera > genCameraDefaultCalibration()
a general SFM factor with an unknown calibration
set noclip points set clip one set noclip two set bar set border lt lw set xdata set ydata set zdata set x2data set y2data set boxwidth set dummy x
PinholeCamera< Cal3_S2 > GeneralCamera
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Vector unwhitenedError(const Values &x, boost::optional< std::vector< Matrix > & > H=boost::none) const override
noiseModel::Base::shared_ptr SharedNoiseModel
The most common 5DOF 3D->2D calibration.
JacobianFactor factor1(keyX, A11, b1, noiseModel::Isotropic::Sigma(2, sigma1))