38 using namespace gtsam;
53 emplace_shared<Projection>(
z,
model,
X(i),
L(j));
72 double U1 = rand() / (double) (RAND_MAX);
73 double U2 = rand() / (double) (RAND_MAX);
76 S = V1 * V1 + V2 * V2;
78 return sqrt(-2.
f * (
double)
log(S) / S) * V1;
87 vector<Point3> landmarks;
88 landmarks.push_back(
Point3(-1., -1., z));
89 landmarks.push_back(
Point3(-1., 1., z));
90 landmarks.push_back(
Point3(1., 1., z));
91 landmarks.push_back(
Point3(1., -1., z));
92 landmarks.push_back(
Point3(-1.5, -1.5, 1.5 * z));
93 landmarks.push_back(
Point3(-1.5, 1.5, 1.5 * 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(-2., -2., 2 * z));
97 landmarks.push_back(
Point3(-2., 2., 2 * z));
98 landmarks.push_back(
Point3(2., 2., 2 * z));
99 landmarks.push_back(
Point3(2., -2., 2 * z));
104 vector<GeneralCamera>
X;
111 const Cal3_S2 K(640, 480, 0.1, 320, 240);
112 vector<GeneralCamera>
X;
119 const vector<GeneralCamera>& cameras,
const vector<Point3>& landmarks) {
121 for (
size_t i = 0;
i < landmarks.size(); ++
i)
122 ordering->push_back(
L(
i));
123 for (
size_t i = 0;
i < cameras.size(); ++
i)
124 ordering->push_back(
X(
i));
132 const Symbol cameraFrameNumber(
'x', 1), landmarkNumber(
'l', 1);
134 std::shared_ptr<Projection>
factor1(
135 new Projection(z, sigma, cameraFrameNumber, landmarkNumber));
137 std::shared_ptr<Projection>
factor2(
138 new Projection(z, sigma, cameraFrameNumber, landmarkNumber));
169 for (
size_t j = 0;
j < cameras.size(); ++
j) {
170 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
176 const size_t nMeasurements = cameras.size() * landmarks.size();
179 const double noise =
baseline * 0.1;
181 for (
size_t i = 0;
i < cameras.size(); ++
i)
184 for (
size_t i = 0; i < landmarks.size(); ++
i) {
206 for (
size_t j = 0;
j < cameras.size(); ++
j) {
207 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
213 const size_t nMeasurements = cameras.size() * landmarks.size();
216 const double noise =
baseline * 0.1;
218 for (
size_t i = 0;
i < cameras.size(); ++
i)
222 for (
size_t i = 0; i < landmarks.size(); ++
i) {
229 values.
insert(
L(i), landmarks[i]);
234 const double reproj_error = 1
e-5;
239 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
249 const double noise =
baseline * 0.1;
251 for (
size_t i = 0;
i < cameras.size(); ++
i) {
252 for (
size_t j = 0;
j < landmarks.size(); ++
j) {
253 Point2 z = cameras[
i].project(landmarks[
j]);
258 const size_t nMeasurements = landmarks.size() * cameras.size();
261 for (
size_t i = 0;
i < cameras.size(); ++
i)
264 for (
size_t j = 0;
j < landmarks.size(); ++
j) {
271 for (
size_t i = 0; i < cameras.size(); ++
i)
274 const double reproj_error = 1
e-5;
279 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
290 for (
size_t j = 0;
j < cameras.size(); ++
j) {
291 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
297 const size_t nMeasurements = landmarks.size() * cameras.size();
300 for (
size_t i = 0;
i < cameras.size(); ++
i) {
301 const double rot_noise = 1
e-5, trans_noise = 1
e-3, focal_noise = 1,
308 trans_noise, trans_noise, trans_noise,
309 focal_noise, focal_noise,
311 trans_noise, trans_noise
313 values.
insert(
X(
i), cameras[
i].retract(delta));
317 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
323 for (
size_t i = 0;
i < landmarks.size(); ++
i)
326 const double reproj_error = 1
e-5;
331 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
341 for (
size_t j = 0;
j < cameras.size(); ++
j) {
342 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
348 const size_t nMeasurements = cameras.size() * landmarks.size();
351 const double noise =
baseline * 0.1;
353 for (
size_t i = 0;
i < cameras.size(); ++
i)
357 for (
size_t i = 0; i < landmarks.size(); ++
i) {
370 noiseModel::Isotropic::Sigma(1, 10.));
372 const double reproj_error = 1
e-5;
377 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
387 noiseModel::Isotropic::Sigma(1, 1.));
389 noiseModel::Isotropic::Sigma(6, 1.));
413 noiseModel::Isotropic::Sigma(6, 1.));
416 noiseModel::Isotropic::Sigma(1, 1.));
418 noiseModel::Isotropic::Sigma(6, 1.));
451 vector<SharedNoiseModel> models;
454 using namespace noiseModel;
455 Rot2 R = Rot2::fromAngle(0.3);
458 Constrained::All(2), Gaussian::Covariance(cov)};
466 GaussianFactor::shared_ptr
expected =
467 factor.NoiseModelFactor::linearize(values);
468 GaussianFactor::shared_ptr actual = factor.
linearize(values);
474 HessianFactor expectedHessian(*expected), actualHessian(*actual);
501 for (
size_t i = 0;
i < cameras.size(); ++
i)
503 for (
size_t j = 0;
j < landmarks.size(); ++
j)
506 for (
size_t i = 0; i < cameras.size(); ++
i) {
507 for (
size_t j = 0; j < landmarks.size(); ++
j) {
508 Point2 z = cameras[
i].project(landmarks[j]);
510 std::make_shared<Projection>(
z,
sigma1,
X(i),
L(j));
511 GaussianFactor::shared_ptr factor = nonlinear->linearize(values);
NonlinearEquality< Point3 > Point3Constraint
NonlinearEquality< GeneralCamera > CameraConstraint
virtual const Values & optimize()
Concept check for values that can be used in unit tests.
IsDerived< DERIVEDFACTOR > emplace_shared(Args &&... args)
Emplace a shared pointer to factor of given type.
static int runAllTests(TestResult &result)
Matrix augmentedInformation() const override
Factor Graph consisting of non-linear factors.
noiseModel::Diagonal::shared_ptr model
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
Rot2 R(Rot2::fromAngle(0.1))
static vector< Point3 > genPoint3()
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
static const SharedNoiseModel sigma1(noiseModel::Unit::Create(2))
static const Point3 pt(1.0, 2.0, 3.0)
NonlinearFactorGraph graph
EIGEN_DEVICE_FUNC const LogReturnType log() const
std::shared_ptr< GaussianFactor > linearize(const Values &values) const override
Linearize using fixed-size matrices.
Rot3 is a 3D rotation represented as a rotation matrix if the preprocessor symbol GTSAM_USE_QUATERNIO...
static enum @1107 ordering
double absoluteErrorTol
The maximum absolute error decrease to stop iterating (default 1e-5)
static const SmartProjectionParams params
static std::shared_ptr< Ordering > getOrdering(const vector< GeneralCamera > &cameras, const vector< Point3 > &landmarks)
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.
static Point2 measurement(323.0, 240.0)
std::shared_ptr< This > shared_ptr
TEST(GeneralSFMFactor, equals)
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.)
The most common 5DOF 3D->2D calibration.
Vector unwhitenedError(const Values &x, OptionalMatrixVecType H=nullptr) const override
static const double baseline
void addMeasurement(int i, int j, const Point2 &z, const SharedNoiseModel &model)
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)
static const double sigma
static double getGaussian()
void insert(Key j, const Value &val)
Jet< T, N > sqrt(const Jet< T, N > &f)
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
double error() const
return error in current optimizer state
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
noiseModel::Base::shared_ptr SharedNoiseModel
The most common 5DOF 3D->2D calibration.