【SLAM十四讲】实战错误解决

ch5

imageBasics

首先需要把cmakelists补全:
在这里插入图片描述

运行报错:terminate called after throwing an instance of ‘std::logic_error’
what(): basic_string::_M_construct null not valid
解决方法:
打开终端创建build
需要输入图片路径,否则是空指针
在这里插入图片描述

之后发现报错:
Failed to load module “canberra-gtk-module”
解决方法:
在终端输入: sudo apt-get install libcanberra-gtk-module
之后再重新执行即可

运行undistortImage时又报错:
在这里插入图片描述
解决方法:
在undistortImage.cpp 里将路径改为绝对路径

string image_file = "/home/jy/slambook2/ch5/imageBasics/distorted.png";   // 请确保路径正确

至此该文件下两个程序均可成功运行,下图为终端输入的命令:若运行第一个,则最后一行为
./imageBasics …/ubuntu.png

在这里插入图片描述

rgbd

首先在rgbd文件下新建build文件,编译
发现报错:
– Found Threads: TRUE
CMake Warning (dev) in CMakeLists.txt:
No cmake_minimum_required command is present. A line of code such as

cmake_minimum_required(VERSION 3.22)

should be added at the top of the file. The version specified may be lower
if you wish to support older CMake versions for this project. For more
information run “cmake --help-policy CMP0000”.
This warning is for project developers. Use -Wno-dev to suppress it.

– Configuring done
CMake Warning (dev) at CMakeLists.txt:6 (add_executable):
Policy CMP0003 should be set before this line. Add code such as

if(COMMAND cmake_policy)
  cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

as early as possible but after the most recent call to
cmake_minimum_required or cmake_policy(VERSION). This warning appears
because target “joinMap” links to some libraries for which the linker must
search:

rt

and other libraries with known full path:

/usr/local/lib/libpango_glgeometry.so

CMake is adding directories in the second list to the linker search path in
case they are needed to find libraries from the first list (for backwards
compatibility with CMake 2.4). Set policy CMP0003 to OLD or NEW to enable
or disable this behavior explicitly. Run “cmake --help-policy CMP0003” for
more information.
This warning is for project developers. Use -Wno-dev to suppress it.

解决方法:
初步修改cmakelists:
在这里插入图片描述并修改joinMap.cpp
21行:

ifstream fin(“…/pose.txt”);

28行:

boost::format fmt(“…/%s/%d.%s”); //图像文件格式

之后编译运行发现报错:

make[2]: *** [CMakeFiles/joinMap.dir/build.make:76:CMakeFiles/joinMap.dir/joinMap.cpp.o] 错误 1
make[1]: *** [CMakeFiles/Makefile2:83:CMakeFiles/joinMap.dir/all] 错误 2
make: *** [Makefile:91:all] 错误 2

在这里插入图片描述
此时再次修改cmakelists为:

cmake_minimum_required(VERSION 3.0)
project(rgbd)
find_package(Sophus REQUIRED)
include_directories( S o p h u s I N C L U D E D I R S ) f i n d p a c k a g e ( O p e n C V R E Q U I R E D ) i n c l u d e d i r e c t o r i e s ( {Sophus_INCLUDE_DIRS}) find_package(OpenCV REQUIRED) include_directories( SophusINCLUDEDIRS)findpackage(OpenCVREQUIRED)includedirectories({OpenCV_INCLUDE_DIRS})
find_package(Pangolin REQUIRED)
add_executable(joinMap joinMap.cpp)
target_link_libraries(joinMap ${OpenCV_LIBS} ${Pangolin_LIBRARIES} ${Sophus_INCLUDE_DIRS} fmt)

至此,该程序成功运行
在这里插入图片描述

stereo

首先,将cmakelists作以下修改:

cmake_minimum_required(VERSION 3.0)
project(stereo)
find_package(Pangolin REQUIRED)
include_directories(“/usr/include/eigen3”)
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})
add_executable(stereoVision stereoVision.cpp)
target_link_libraries(stereoVision ${OpenCV_LIBS} ${Pangolin_LIBRARIES})

编译运行报错:

[ WARN:0@0.000] global /home/jy/公共的/opencv-4.5.5/modules/imgcodecs/src/loadsave.cpp (239) findDecoder imread_(‘./left.png’): can’t open/read file: check file path/integrity
[ WARN:0@0.001] global /home/jy/公共的/opencv-4.5.5/modules/imgcodecs/src/loadsave.cpp (239) findDecoder imread_(‘./right.png’): can’t open/read file: check file path/integrity
terminate called after throwing an instance of ‘cv::Exception’
what(): OpenCV(4.5.5) /home/jy/公共的/opencv-4.5.5/modules/imgproc/src/median_blur.dispatch.cpp:283: error: (-215:Assertion failed) !_src0.empty() in function ‘medianBlur’
已放弃 (核心已转储)

在这里插入图片描述

解决方法:
在stereoVision.cpp中12、13行修改文件路径为

// 文件路径
string left_file = "/home/jy/slambook2/ch5/stereo/left.png";
string right_file = "/home/jy/slambook2/ch5/stereo/right.png";

至此,该程序成功运行

ch6

cere安装

首先参考官网
http://ceres-solver.org/installation.html
但make install报错:
CMake Error at cmake_install.cmake:46 (file):
file cannot create directory: /usr/local/lib/cmake/Ceres. Maybe need
administrative privileges.
在这里插入图片描述
解决方法:

sudo make install

此处是没管理员权限,加上sudo即可

g2o安装

首先安装依赖项

sudo apt-get install libsuitesparse-dev qtdeclarative5-dev qt5-qmake libqglviewer-dev-qt5 libeigen3-dev

git clone https://gitcode.net/mirrors/rainerkuemmerle/g2o
cd g2o
mkdir build
cd build
cmake ..
make -j6  
sudo make install

ch6程序

报错过长此处省略
解决方法:
在cmakelists中修改

cmake_minimum_required(VERSION 3.5)

即可

ch7

首先修改cmakelists
第一行:

cmake_minimum_required(VERSION 3.5)

第九行:

find_package(OpenCV REQUIRED)

orb_cv

发现有以下错误:

 Mat img_2 = imread(argv[2], CV_LOAD_IMAGE_COLOR);

在这里插入图片描述
解决方法,将代码改为:

  Mat img_1 = imread(argv[1], IMREAD_COLOR);
  Mat img_2 = imread(argv[2], 1);

两种形式均可

然后点击此处:
在这里插入图片描述打开页面后选择第三第四个按下图:
在这里插入图片描述
然后OK,再次运行。至此,该程序成功运行
在这里插入图片描述

orb_self

首先打开后发现此处报错:

在这里插入图片描述解决方法:
进行强制类型转换

cv::DMatch m{static_cast<int>(i1), 0, 256};

然后再进行上个程序在run的操作,运行。
至此,该程序成功运行
在这里插入图片描述

pose_estimation_2d2d

首先修改pose_estimation_2d2d.cpp 36、37行为:

//-- 读取图像
  Mat img_1 = imread(argv[1], IMREAD_COLOR);
  Mat img_2 = imread(argv[2], IMREAD_COLOR);//此类修改不再重复

其次,pose_estimation_2d2d.cpp 144行有以下报错:
在这里插入图片描述
解决方法:修改为

fundamental_matrix = findFundamentalMat(points1, points2, FM_8POINT);

然后再进行上个程序在run的操作,运行。
至此,该程序成功运行

pose_estimation_3d2d

首先,pose_estimation_3d2d.cpp 第64行有如下报错:
在这里插入图片描述
解决方法:
修改代码为

Mat d1 = imread(argv[3], IMREAD_UNCHANGED);

其次,pose_estimation_3d2d.cpp 第271行有如下报错:
在这里插入图片描述解决方法:
在cmakelists中添加

set( CMAKE_CXX_STANDARD 14)

至此,该程序成功运行。

pose_estimation_3d3d

关于此程序报错的修改与上述程序重复,此处不再赘述,但需注意pose_estimation_3d2d和pose_estimation_3d3d此处的program arguments应如下图所示:
在这里插入图片描述

ch8

本讲有点乱,报错很多,做了多处修改,有些报错并未截图复制而是省略

optical_flow

cmakelists作以下修改:

#set(CMAKE_CXX_FLAGS “-std=c++11 ${SSE_FLAGS} -g -O3 -march=native”)//注释掉

首先,optical_flow.cpp 第145、154、163行均报错:
在这里插入图片描述
解决方法:
修改代码为

cv::cvtColor(img2, img2_multi, cv::COLOR_GRAY2BGR);//下一个程序和此处相同不再赘述

此程序14、15行修改路径:

string file_1 = "/home/jy/slambook2/ch8/LK1.png";  // first image
string file_2 = "/home/jy/slambook2/ch8/LK2.png";  // second image

direct_method

发现运行报错:
在这里插入图片描述解决方法:
第15、16行将路径改为绝对路径

string left_file = "/home/jy/slambook2/ch8/left.png";
string disparity_file = "/home/jy/slambook2/ch8/disparity.png";

17行改为:

boost::format fmt_others("../%06d.png");  //多加一个.

cmakelists:加fmt

target_link_libraries(direct_method ${OpenCV_LIBS} ${Pangolin_LIBRARIES} fmt)

做上述所有修改后,本讲两个程序均可运行

ch9

查了很多文章,放弃了,用的这篇文章给的代码

改github上的代码改了很久,依然运行不了,害

  • 6
    点赞
  • 28
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值