天天看点

高翔的g2o_ba_example在ubuntu18环境下报错

关于高翔的g2o_ba_example在ubuntu18环境下报错的问题,我是用的opencv4,g2o版本也比较新,所以源码存在问题,修改方法是

第一部分报错地方修改

// 使用Cholmod中的线性方程求解器

g2o::BlockSolver_6_3::LinearSolverType* linearSolver = new g2o::LinearSolverCholmod<g2o::BlockSolver_6_3::PoseMatrixType> ();

// 6*3 的参数

//g2o::BlockSolver_6_3* block_solver = new g2o::BlockSolver_6_3( linearSolver );

g2o::BlockSolver_6_3* block_solver = new g2o::BlockSolver_6_3( unique_ptr<g2o::BlockSolver_6_3::LinearSolverType>(linearSolver) ); //矩阵块求解器

// L-M 下降

//g2o::OptimizationAlgorithmLevenberg* algorithm = new g2o::OptimizationAlgorithmLevenberg( block_solver );

g2o::OptimizationAlgorithmLevenberg* algorithm = new g2o::OptimizationAlgorithmLevenberg( unique_ptr<g2o::BlockSolver_6_3>(block_solver)); //迭代算法

第二部分报错地方修改

cv::Ptr<cv::FeatureDetector> detector = cv::ORB::create();

cv::Ptr<cv::DescriptorExtractor> descriptor = cv::ORB::create();

detector->detect(img1, kp1);

detector->detect(img2, kp2);

descriptor->compute(img1, kp1, desp1);

descriptor->compute(img2, kp2, desp2);

取代:

//cv::ORB orb;

//orb( img1, cv::Mat(), kp1, desp1 )

//orb( img2, cv::Mat(), kp2, desp2 )

第三个问题是虽然能通过正常编译,但是一运行就报错:double free or corruption (out)

解决方法是将cmakelist中开头set( CMAKE_CXX_FLAGS "-std=c++11 -march=native -O3" )

改成

set( CMAKE_CXX_FLAGS "-std=c++11 -O3" )

此时就可以完美运行