44 {
45 int num_points = 0;
46
47
48 if (argc > 1) num_points = atoi(argv[1]);
49
50 double euc_noise = 0.1;
51 double pix_noise = 1.0;
52
53
56
57
60 std::make_unique<
62
64
65 vector<Vector3d> true_points;
66 for (size_t i = 0; i < 1000; ++i) {
67 true_points.push_back(
71 }
72
73
74 Vector2d focal_length(500, 500);
75 Vector2d principal_point(320, 240);
76 double baseline = 0.075;
77
78
80 principal_point[1], baseline);
81
82
83 int vertex_id = 0;
84 for (size_t i = 0; i < 2; ++i) {
85
86 Vector3d t(0, 0, i);
87 Quaterniond q;
88 q.setIdentity();
89
90 Eigen::Isometry3d cam;
91 cam = q;
92 cam.translation() = t;
93
94
98
99 cerr << t.transpose() << " | " << q.coeffs().transpose() << endl;
100
101
103
104
106
107
109
110 vertex_id++;
111 }
112
113
114 for (size_t i = 0; i < true_points.size(); ++i) {
115
120
121
122 Vector3d pt0, pt1;
123 pt0 = vp0->
estimate().inverse() * true_points[i];
124 pt1 = vp1->
estimate().inverse() * true_points[i];
125
126
130
134
135
136 Vector3d nm0, nm1;
137 nm0 << 0, i, 1;
138 nm1 << 0, i, 1;
139 nm0.normalize();
140 nm1.normalize();
141
144
147
150
152
159
160
161
163
164
165
166
167
168
169
171 }
172
173
174
175 true_points.clear();
176 for (int i = 0; i < num_points; ++i) {
177 true_points.push_back(
181 }
182
183
184 for (size_t i = 0; i < true_points.size(); ++i) {
186
187 v_p->
setId(vertex_id++);
193
195
196 for (size_t j = 0; j < 2; ++j) {
197 Vector3d z;
199 ->mapPoint(z, true_points.at(i));
200
201 if (z[0] >= 0 && z[1] >= 0 && z[0] < 640 && z[1] < 480) {
205
207
209
211 optimizer.
vertices().find(j)->second);
212
214
216
217
218
219
221 }
222 }
223 }
224
225
228 Eigen::Isometry3d cam = vc->
estimate();
229 cam.translation() = Vector3d(-0.1, 0.1, 0.2);
233 cout <<
"Initial chi2 = " << FIXED(optimizer.
chi2()) << endl;
234
236
238
239 cout << endl << "Second vertex should be near 0,0,1" << endl;
240 cout << dynamic_cast<VertexSE3*>(optimizer.
vertices().find(0)->second)
241 ->estimate()
242 .translation()
243 .transpose()
244 << endl;
245 cout << dynamic_cast<VertexSE3*>(optimizer.
vertices().find(1)->second)
246 ->estimate()
247 .translation()
248 .transpose()
249 << endl;
250}
EIGEN_STRONG_INLINE const Measurement & measurement() const
accessor functions for the measurement represented by the edge
virtual void setMeasurement(const Measurement &m)
EIGEN_STRONG_INLINE const InformationType & information() const
information matrix of the constraint
const EstimateType & estimate() const
return the current estimate of the vertex
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
Point vertex, XYZ, is in types_sba.
const VertexContainer & vertices() const
const VertexIDMap & vertices() const
linear solver which uses the sparse Cholesky solver from Eigen
A general case Vertex for optimization.
virtual void setId(int id)
void setFixed(bool fixed)
true => this node should be considered fixed during the optimization
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
Implementation of the Levenberg Algorithm.
static double gaussRand(double mean, double sigma)
static double uniformRand(double lowerBndr, double upperBndr)
void computeActiveErrors()
int optimize(int iterations, bool online=false)
void setVerbose(bool verbose)
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
void setAlgorithm(OptimizationAlgorithm *algorithm)
Vertex for a tracked point in space.
Stereo camera vertex, derived from SE3 class. Note that we use the actual pose of the vertex as its p...
static void setKcam(double fx, double fy, double cx, double cy, double tx)
3D pose Vertex, represented as an Isometry3
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
double chi2() const
returns the chi2 of the current configuration