288 string outputFilename;
289 string inputFilename;
290 string statsFilename;
292 arg.
param(
"i", maxIterations, 5,
"perform n iterations");
293 arg.
param(
"o", outputFilename,
"",
"write points into a vrml file");
294 arg.
param(
"pcg", usePCG,
false,
"use PCG instead of the Cholesky");
295 arg.
param(
"v", verbose,
false,
"verbose output of the optimization process");
296 arg.
param(
"stats", statsFilename,
"",
"specify a file for the statistics");
297 arg.
paramLeftOver(
"graph-input", inputFilename,
"",
"file which will be processed");
302 #ifdef G2O_HAVE_CHOLMOD 303 string choleskySolverName =
"CHOLMOD";
305 #elif defined G2O_HAVE_CSPARSE 306 string choleskySolverName =
"CSparse";
309 #error neither CSparse nor CHOLMOD are available 316 cout <<
"Using PCG" << endl;
317 linearSolver =
new BalLinearSolverPCG();
319 cout <<
"Using Cholesky: " << choleskySolverName << endl;
320 BalLinearSolver* cholesky =
new BalLinearSolver();
321 cholesky->setBlockOrdering(
true);
322 linearSolver = cholesky;
324 BalBlockSolver* solver_ptr =
new BalBlockSolver(linearSolver);
328 if (statsFilename.size() > 0){
332 vector<VertexPointBAL*> points;
333 vector<VertexCameraBAL*> cameras;
336 cout <<
"Loading BAL dataset " << inputFilename << endl;
338 ifstream ifs(inputFilename.c_str());
339 int numCameras, numPoints, numObservations;
340 ifs >> numCameras >> numPoints >> numObservations;
342 cerr << PVAR(numCameras) <<
" " << PVAR(numPoints) <<
" " << PVAR(numObservations) << endl;
345 cameras.reserve(numCameras);
346 for (
int i = 0; i < numCameras; ++i, ++id) {
350 cameras.push_back(cam);
353 points.reserve(numPoints);
354 for (
int i = 0; i < numPoints; ++i, ++id) {
358 bool addedVertex = optimizer.
addVertex(p);
360 cerr <<
"failing adding vertex" << endl;
366 for (
int i = 0; i < numObservations; ++i) {
367 int camIndex, pointIndex;
369 ifs >> camIndex >> pointIndex >> obsX >> obsY;
371 assert(camIndex >= 0 && (
size_t)camIndex < cameras.size() &&
"Index out of bounds");
373 assert(pointIndex >= 0 && (
size_t)pointIndex < points.size() &&
"Index out of bounds");
381 bool addedEdge = optimizer.
addEdge(e);
383 cerr <<
"error adding edge" << endl;
388 Eigen::VectorXd cameraParameter(9);
389 for (
int i = 0; i < numCameras; ++i) {
390 for (
int j = 0; j < 9; ++j)
391 ifs >> cameraParameter(j);
398 for (
int i = 0; i < numPoints; ++i) {
399 ifs >> p(0) >> p(1) >> p(2);
406 cout <<
"done." << endl;
408 cout <<
"Initializing ... " << flush;
410 cout <<
"done." << endl;
412 cout <<
"Start to optimize" << endl;
415 if (statsFilename!=
""){
416 cerr <<
"writing stats to file \"" << statsFilename <<
"\" ... ";
417 ofstream fout(statsFilename.c_str());
419 for (
size_t i=0; i<bsc.size(); i++)
420 fout << bsc[i] << endl;
421 cerr <<
"done." << endl;
425 if (outputFilename.size() > 0) {
426 ofstream fout(outputFilename.c_str());
428 <<
"#VRML V2.0 utf8\n" 430 <<
" appearance Appearance {\n" 431 <<
" material Material {\n" 432 <<
" diffuseColor " << 1 <<
" " << 0 <<
" " << 0 <<
"\n" 433 <<
" ambientIntensity 0.2\n" 434 <<
" emissiveColor 0.0 0.0 0.0\n" 435 <<
" specularColor 0.0 0.0 0.0\n" 436 <<
" shininess 0.2\n" 437 <<
" transparency 0.0\n" 440 <<
" geometry PointSet {\n" 441 <<
" coord Coordinate {\n" 443 for (vector<VertexPointBAL*>::const_iterator it = points.begin(); it != points.end(); ++it) {
444 fout << (*it)->estimate().transpose() << endl;
446 fout <<
" ]\n" <<
" }\n" <<
"}\n" <<
" }\n";
const BatchStatisticsContainer & batchStatistics() const
Command line parsing of argc and argv.
void setComputeBatchStatistics(bool computeBatchStatistics)
Implementation of the Levenberg Algorithm.
int optimize(int iterations, bool online=false)
virtual void setMeasurement(const Measurement &m)
linear solver using PCG, pre-conditioner is block Jacobi
void setVertex(size_t i, Vertex *v)
virtual void setId(int id)
sets the id of the node in the graph be sure that the graph keeps consistent after changing the id ...
bool parseArgs(int argc, char **argv, bool exitOnError=true)
void setVerbose(bool verbose)
linear solver which uses CSparse
void paramLeftOver(const std::string &name, std::string &p, const std::string &defValue, const std::string &desc, bool optional=false)
void setAlgorithm(OptimizationAlgorithm *algorithm)
EIGEN_STRONG_INLINE void setInformation(const InformationType &information)
void param(const std::string &name, bool &p, bool defValue, const std::string &desc)
basic solver for Ax = b which has to reimplemented for different linear algebra libraries ...
void setEstimate(const EstimateType &et)
set the estimate for the vertex also calls updateCache()
void setMarginalized(bool marginalized)
true => this node should be marginalized out during the optimization
edge representing the observation of a world feature by a camera
Implementation of a solver operating on the blocks of the Hessian.
virtual bool initializeOptimization(HyperGraph::EdgeSet &eset)
virtual bool addEdge(HyperGraph::Edge *e)
virtual bool addVertex(HyperGraph::Vertex *v, Data *userData)
std::vector< G2OBatchStatistics > BatchStatisticsContainer
camera vertex which stores the parameters for a pinhole camera