⼀起做RGB-DSLAM(7)BUG笔记
跟做⾼博的《⼀起做RGB-D SLAM》系列时,出现了挺多bug的(主要因为⾃⼰还是个⼩⽩),在此记录下解决过程。
(ubuntu18.04,opencv3.4.9)
⼀起做RGB-D SLAM(7):
1.安装g20
参照
<: no matching function for call to ‘g2o::BlockSolver<g2o::BlockSolverTraits<6, 3> >::BlockSolver(SlamLinearSolver*&)’ SlamBlockSolver* blockSolver = new SlamBlockSolver( linearSolver );
这个错误在说过,因为g2o新版本和旧版本在智能指针上不兼容导致的。把src/slam.cpp的g2o初始化部分(下图⽩框处内容)改为:
unique_ptr<SlamBlockSolver::LinearSolverType> linearSolver (new SlamLinearSolver());
unique_ptr<SlamBlockSolver> blockSolver (new SlamBlockSolver(move(linearSolver)));
g2o::OptimizationAlgorithmLevenberg* solver =new g2o::OptimizationAlgorithmLevenberg(move(blockSolver));
<: ‘RED’ was not declared in this scope cout<<RED"Not enough inliers."<<endl;error:
‘RESET’ was not declared in this scope cout<<RESET"Too close, not a keyframe"<<endl;error:‘GREEN’ was not declared in this scope cout<<GREEN"This is a new keyframe"<<endl;error:‘RESET’ was not declared in this scope cout<<RESET"optimizing pose graph, vertices: "
<<globalOptimizer.vertices().size()<<endl;
对这些颜⾊进⾏定义即可,在include/slamBase.h的末尾,添加:
#define RESET "\033[0m"
#define BLACK "\033[30m"
#define RED "\033[31m"
#define GREEN "\033[32m"
#define YELLOW "\033[33m"
#define BLUE "\033[34m"
#define MAGENTA "\033[35m"
#define CYAN "\033[36m"
#define WHITE "\033[37m"
#define BOLDBLACK "\033[1m\033[30m"
#define BOLDRED "\033[1m\033[31m"
#define BOLDGREEN "\033[1m\033[32m"
#define BOLDYELLOW "\033[1m\033[33m"
<: ‘__gnu_cxx::__alloc_traits<std::allocator >::value_type {aka struct FRAME}’ has no member named ‘frameID’ dynamic_castg2o::VertexSE3*(globalOptimizer.vertex( keyframes[i].frameID ));
说过,在include/slamBase.h⾥(下图⽩框处)加上:
int frameID;
5.slam.cpp:(.text+0x990):
对‘g2o::OptimizationAlgorithmLevenberg::OptimizationAlgorithmLevenberg(std::unique_ptr<g 2o::Solver, std::default_deleteg2o::Solver >)’未定义的引⽤slam.cpp:(.text+0x9b5):
对‘g2o::SparseOptimizer::SparseOptimizer()’未定义的引⽤slam.cpp:(.text+0x9ce):
对‘g2o::SparseOptimizer::setAlgorithm(g2o::OptimizationAlgorithm*)’未定义的引⽤slam.cpp:
(.text+0x9e2):对‘g2o::SparseOptimizer::setVerbose(bool)’未定义的引⽤slam.cpp:
(.text+0x9f7):对‘g2o::VertexSE3::VertexSE3()’未定义的引⽤slam.cpp:(.text+0xeff):
对‘g2o::OptimizableGraph::save(char const*, int) const’未定义的引⽤…
⾥添加的slam⼆进制执⾏⽂件要链接⼀些g2o库,修改为:
ADD_EXECUTABLE(slam slam.cpp)error parse new
TARGET_LINK_LIBRARIES(
slam
slambase
${Opencv_LIBS}
${PCL_LIBRARIES}
g2o_core g2o_types_slam3d g2o_solver_csparse g2o_stuff g2o_csparse_extension ${CSPARSE_LIBRARY})
6.bin/slam: error while loading shared libraries: libg2o_opengl_helper.so: cannot open shared object file: No such file or directory
这个错误是因为链接器不到动态库⽂件libg2o_opengl_helper.so。ld默认的⽬录是/lib和/usr/lib,⽽我的这个库⽂件
在/usr/local/lib,因此需要在⾥加上⼀句:
LINK_DIRECTORIES("/usr/local/lib")
7.parameter file does not exist. Parameter name start_index not found! Parameter name
end_index not found! Initializing … Parameter name rgb_dir not found! Parameter name depth_dir not found! Parameter name rgb_extension not found! Parameter name
depth_extension not found! Parameter name detector not found! Parameter name descriptor not found!
这个错误应该很明显了,配置⽂件没读取到,我是把配置⽂件放到data⽬录下了,所以要把include/slamBase.h参数读取类⾥
把"./"改为:
""
8.Not enough inliers.Reading files 3 Not enough inliers.Reading files 4 Not enough inliers.
所有数据都出错的话,⼤概率应该是数据路径出了问题,在⾥,把数据所在⽬录改为:
rgb_dir=data/rgb_png/
rgb_extension=.png
depth_dir=data/depth_png/
depth_extension=.png
ps:也可以改为绝对路径。
<: (-2:Unspecified error) in function ‘void cvFindExtrinsicCameraParams2(const CvMat*, const CvMat*, const CvMat*, const CvMat*, CvMat*, CvMat*, int)’> DLT algorithm needs at least 6 points for pose estimation from 3D-2D point correspondences. (expected: ‘count >= 6’), where> ‘count’ is 5 > must be greater than or equal to > ‘6’ is 6 已放弃 (核⼼已转储)————运⾏bin/slam时出错。
这个问题和⾥的不⼀样,修改ransac的内部阈值没⽤。
这个问题困扰我了好久,明明传⼊的obj和img点对有⼏⼗对,但是在solvepnpransac内部调⽤cvFindExtrinsicCameraParams2函数时候,就变成了5对。修改了迭代次数、ransac阈值、置信度什么的都没⽤。查看opencv相关源码时候,发现了⼀个地⽅(下图⽩框处):
这⾥就是报错的地⽅,⽽他在else⾥ 灵机⼀动,到对应的if,发现是在判断solvepnpransac()的⼀个参数值是否为
true(useExtrinsicGuess参数),抱着试⼀试的⼼态,把对应的参数改为true。。。。。。结果就运⾏成功了?what?
~~~~解决⽅法~~~~: ⾸先要保证,点对数⽬⼤于5,在src/slamBase.cpp⾥(下图⽩框处)加上两个判断:优化匹配点对数⽬⾄少要6对以上:
if(goodMatches.size()<=5)
{
result.inliers =-1;
return result;
}
输⼊solvepnpransac函数的前⼀帧三维点对和后⼀帧⼆维点对数⽬⾄少要⼤于5(注意,这⾥⼀定要⼤于5对):
if(pts_obj.size()<=5|| pts_img.size()<=5)
{
result.inliers =-1;
return result;
}
然后将src/slamBase.cpp(下图⽩框处)改为:
cv::solvePnPRansac( pts_obj, pts_img, cameraMatrix, cv::Mat(), rvec, tvec,true,100,1.0,0.99, inliers );
这个bug具体的出错原因⾄今不明⽩,希望有⼤佬可以在评论区答疑解惑⼀下,⼤家有其他解决⽅法也欢迎交流哈。
运⾏结果不错,优化的⼈影也可以看出来,奶斯!
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。
发表评论