31 #include <boost/shared_ptr.hpp> 38 using namespace gtsam;
54 push_back(boost::make_shared<Projection>(z, model,
X(i),
L(j)));
73 double U1 = rand() / (double) (RAND_MAX);
74 double U2 = rand() / (double) (RAND_MAX);
77 S = V1 * V1 + V2 * V2;
79 return sqrt(-2.
f * (
double)
log(S) / S) * V1;
88 const Symbol cameraFrameNumber(
'x', 1), landmarkNumber(
'l', 1);
90 boost::shared_ptr<Projection>
factor1(
91 new Projection(z, sigma, cameraFrameNumber, landmarkNumber));
93 boost::shared_ptr<Projection>
factor2(
94 new Projection(z, sigma, cameraFrameNumber, landmarkNumber));
103 boost::shared_ptr<Projection> factor(
new Projection(z, sigma,
X(1),
L(1)));
120 vector<Point3> landmarks;
121 landmarks.push_back(
Point3(-1., -1., z));
122 landmarks.push_back(
Point3(-1., 1., z));
123 landmarks.push_back(
Point3(1., 1., z));
124 landmarks.push_back(
Point3(1., -1., z));
125 landmarks.push_back(
Point3(-1.5, -1.5, 1.5 * z));
126 landmarks.push_back(
Point3(-1.5, 1.5, 1.5 * z));
127 landmarks.push_back(
Point3(1.5, 1.5, 1.5 * z));
128 landmarks.push_back(
Point3(1.5, -1.5, 1.5 * z));
129 landmarks.push_back(
Point3(-2., -2., 2 * z));
130 landmarks.push_back(
Point3(-2., 2., 2 * z));
131 landmarks.push_back(
Point3(2., 2., 2 * z));
132 landmarks.push_back(
Point3(2., -2., 2 * z));
137 vector<GeneralCamera> cameras;
147 vector<GeneralCamera> cameras;
156 const std::vector<GeneralCamera>& cameras,
157 const std::vector<Point3>& landmarks) {
159 for (
size_t i = 0;
i < landmarks.size(); ++
i)
160 ordering->push_back(
L(
i));
161 for (
size_t i = 0;
i < cameras.size(); ++
i)
162 ordering->push_back(
X(
i));
167 TEST( GeneralSFMFactor_Cal3Bundler, optimize_defaultK ) {
174 for (
size_t j = 0;
j < cameras.size(); ++
j) {
175 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
181 const size_t nMeasurements = cameras.size() * landmarks.size();
184 const double noise =
baseline * 0.1;
186 for (
size_t i = 0;
i < cameras.size(); ++
i)
189 for (
size_t i = 0; i < landmarks.size(); ++
i) {
206 TEST( GeneralSFMFactor_Cal3Bundler, optimize_varK_SingleMeasurementError ) {
211 for (
size_t j = 0;
j < cameras.size(); ++
j) {
212 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
218 const size_t nMeasurements = cameras.size() * landmarks.size();
221 const double noise =
baseline * 0.1;
223 for (
size_t i = 0;
i < cameras.size(); ++
i)
227 for (
size_t i = 0; i < landmarks.size(); ++
i) {
234 values.
insert(
L(i), landmarks[i]);
239 const double reproj_error = 1
e-5;
244 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
248 TEST( GeneralSFMFactor_Cal3Bundler, optimize_varK_FixCameras ) {
254 const double noise =
baseline * 0.1;
256 for (
size_t j = 0;
j < cameras.size(); ++
j) {
257 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
263 const size_t nMeasurements = landmarks.size() * cameras.size();
266 for (
size_t i = 0;
i < cameras.size(); ++
i)
269 for (
size_t i = 0; i < landmarks.size(); ++
i) {
277 for (
size_t i = 0; i < cameras.size(); ++
i)
280 const double reproj_error = 1
e-5;
285 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
289 TEST( GeneralSFMFactor_Cal3Bundler, optimize_varK_FixLandmarks ) {
296 for (
size_t j = 0;
j < cameras.size(); ++
j) {
297 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
303 const size_t nMeasurements = landmarks.size() * cameras.size();
306 for (
size_t i = 0;
i < cameras.size(); ++
i) {
307 const double rot_noise = 1
e-5, trans_noise = 1
e-3, focal_noise = 1,
308 distort_noise = 1
e-3;
314 trans_noise, trans_noise, trans_noise,
315 focal_noise, distort_noise, distort_noise
317 values.
insert(
X(
i), cameras[
i].retract(delta));
321 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
327 for (
size_t i = 0;
i < landmarks.size(); ++
i)
330 const double reproj_error = 1
e-5;
335 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
339 TEST( GeneralSFMFactor_Cal3Bundler, optimize_varK_BA ) {
345 for (
size_t j = 0;
j < cameras.size(); ++
j) {
346 for (
size_t i = 0;
i < landmarks.size(); ++
i) {
352 const size_t nMeasurements = cameras.size() * landmarks.size();
355 const double noise =
baseline * 0.1;
357 for (
size_t i = 0;
i < cameras.size(); ++
i)
361 for (
size_t i = 0; i < landmarks.size(); ++
i) {
374 noiseModel::Isotropic::Sigma(1, 10.));
376 const double reproj_error = 1
e-5;
381 EXPECT(optimizer.
error() < 0.5 * reproj_error * nMeasurements);
TEST(GeneralSFMFactor_Cal3Bundler, equals)
static const SharedNoiseModel sigma1(noiseModel::Unit::Create(2))
static vector< GeneralCamera > genCameraVariableCalibration()
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))
static boost::shared_ptr< Ordering > getOrdering(const std::vector< GeneralCamera > &cameras, const std::vector< Point3 > &landmarks)
EIGEN_DEVICE_FUNC const LogReturnType log() const
EIGEN_DEVICE_FUNC const SqrtReturnType sqrt() const
static Cal3_S2 K(500, 500, 0.1, 640/2, 480/2)
static double getGaussian()
static const Point3 pt(1.0, 2.0, 3.0)
NonlinearFactorGraph graph
NonlinearEquality< Point3 > Point3Constraint
Base class for all pinhole cameras.
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)
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.)
double error() const
return error in current optimizer state
static vector< GeneralCamera > genCameraDefaultCalibration()
static vector< Point3 > genPoint3()
static const double baseline
bool assert_equal(const Matrix &expected, const Matrix &actual, double tol)
GeneralSFMFactor< GeneralCamera, Point3 > Projection
void addMeasurement(int i, int j, const Point2 &z, const SharedNoiseModel &model)
void addCameraConstraint(int j, const GeneralCamera &p)
JacobianFactor factor2(keyX, A21, keyY, A22, b2, noiseModel::Isotropic::Sigma(2, sigma2))
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
void addMeasurement(const int &i, const int &j, const Point2 &z, const SharedNoiseModel &model)
Eigen::Matrix< double, Eigen::Dynamic, 1 > Vector
Calibration used by Bundler.
NonlinearEquality< GeneralCamera > CameraConstraint
PinholeCamera< Cal3Bundler > GeneralCamera
noiseModel::Base::shared_ptr SharedNoiseModel
JacobianFactor factor1(keyX, A11, b1, noiseModel::Isotropic::Sigma(2, sigma1))