ROS Resources: Documentation | Support | Discussion Forum | Index | Service Status | ros @ Robotics Stack Exchange
Ask Your Question
0

G2O BlockSolver Initialization Crash on Unix System

asked 2018-08-02 04:22:34 -0600

Simontraww gravatar image

I have a project which possesses and uses G2O library, it runs on both platforms(win/Unix).

(WINDOW PASSED / UNIX CRASHED)

We can see in both platforms, these lines:

g2o::SparseOptimizer optimizer;
g2o::BlockSolver_6_3::LinearSolverType * linearSolver;

linearSolver = new g2o::LinearSolverDense<g2o::BlockSolver_6_3::PoseMatrixType>();

Next steps, in window os we have this:

g2o::BlockSolver_6_3 * solver_ptr = new g2o::BlockSolver_6_3(linearSolver);
g2o::OptimizationAlgorithmLevenberg* solver = new g2o::OptimizationAlgorithmLevenberg(solver_ptr);

But Unix system can't compile those lines because it says

my_file_G2o.cpp: In member function 'int *Refiner_G2O::refinePose(cv::Mat&, const std::vector<cv::point3_<float> >&, const std::vector<cv::keypoint>&, const cv::Mat&, float, std::vector<int>&)': my_file_G2o.cpp --> no matching function for call to 'g2o::BlockSolver<g2o::blocksolvertraits&lt;6, 3="">::BlockSolver(g2o::BlockSolver<g2o::blocksolvertraits&lt;6, 3="">::LinearSolverType&)'* ^ In file included from G2o/include/g2o/core/block_solver.h:199:0, G2o/include/g2o/core/block_solver.hpp:40:1: note: candidate: g2o::BlockSolver<traits>::BlockSolver(std::unique_ptr<typename traits::linearsolvertype="">) [with Traits = g2o::BlockSolverTraits<6, 3>; typename Traits::LinearSolverType = g2o::LinearSolver<eigen::matrix<double, 6,="" 6,="" 0=""> >] BlockSolver<traits>::BlockSolver(std::unique_ptr<linearsolvertype> linearSolver)

When I see these errors, I complete my Unix code with this new block

auto solver_ptr = g2o::make_unique<g2o::BlockSolver_6_3>(linearSolver); // [SEGFAULT LINE]
auto solver = g2o::make_unique<g2o::OptimizationAlgorithmLevenberg>(solver_ptr);
optimizer.setAlgorithm(solver.get());

So now, I can build/run but I meet a segfault on the line with [SEGFAULT LINE] tag.

I don't understand, why? if someone has an idea I want to understand how in Window it works and not in Unix system, will feel wonderful if you help.

LINUX Version: Ubuntu 16.04
CMAKE Version: 3.11.4

Best regards,

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
0

answered 2018-08-03 06:50:50 -0600

Simontraww gravatar image

SOLVED:

G2O optimise:

g2o::SparseOptimizer optimizer;

auto linearSolver = std::make_unique<g2o::LinearSolverDense<g2o::BlockSolver_6_3::PoseMatrixType>>();

auto solver = new g2o::OptimizationAlgorithmLevenberg(std::make_unique<g2o::BlockSolver_6_3>(std::move(linearSolver)));

optimizer.setAlgorithm(solver);

MISC.H:

template<typename T, typename ...ArgTs>
std::unique_ptr<T> make_unique(ArgTs&& ...args)
{
  return std::unique_ptr<T>(new T(std::forward<ArgTs>(args)...));
};
edit flag offensive delete link more

Comments

Can you explain the MISC.H, do we need to create this file separately or we can add this to the existing file itself ?

Vignesh_93 gravatar image Vignesh_93  ( 2020-12-12 09:49:44 -0600 )edit

Question Tools

Stats

Asked: 2018-08-02 04:22:34 -0600

Seen: 815 times

Last updated: Aug 03 '18