按照书中代码安装依赖项时,出现三个库报错。查阅资料后,将正确的安装步骤整理如下:
打开终端依次输入:
sudo apt-get install build-essential
sudo apt-get install libgtk2.0-dev
sudo apt-get install libvtk6-dev
sudo apt-get install libjpeg-dev
sudo apt-get install libtiff5-dev
sudo apt-get install libjasper-dev
此处报错:errorE: unable to locate libjasper-dev。
大概原因是缺少libjasper-dev的一个依赖包。解决方法:
sudo add-apt-repository "deb http://security.ubuntu.com/ubuntu xenial-security main"
sudo apt update
sudo apt install libjasper1 libjasper-dev
继续安装依赖项:
sudo apt-get install libopenexr-dev
sudo apt-get install libtbb-dev
3.1.0版本的OpenCV我安装不上,转而下载3.4.15版本。点击sources下载压缩包:
点开相应文件夹。解压:
unzip opencv-3.4.15.zip
编译安装:
cd opencv-3.4.15
mkdir build && cd build
cmake ..
make -j4
sudo make install
修改imageBasics下的CMakeLists文件代码:
# 添加C++标准支持
set( CMAKE_CXX_FLAGS "-std=c++11")project(imageBasics)
# 寻找OpenCV库
find_package( OpenCV REQUIRED)# 添加头文件
include_directories(${OpenCV_INCLUDE_DIRS})add_executable(imageBasics imageBasics.cpp)
# 链接OpenCV库
target_link_libraries(imageBasics ${OpenCV_LIBS})add_executable(undistortImage undistortImage.cpp)
# 链接OpenCV库
target_link_libraries(undistortImage ${OpenCV_LIBS})
make完成后,在build终端里执行命令
./imageBasics ../ubuntu.png
若上述相对文件路径执行失败,使用绝对路径,红色字体替换成ubuntu.png的绝对路径(可通过属性进行复制).
./imageBasics home/......../ubuntu.png
运行成功:
在文件undistortImage.cpp中将文件路径修改正确即可:
string image_file = "/home/andyvictory/slambook2/ch5/imageBasics/distorted.png"; // 请确保路径正确
在文件stereoVision.cpp中将文件路径修改正确:(应该是在代码11-13行)
// 文件路径
string left_file = "/home/andyvictory/slambook2/ch5/stereo/left.png";
string right_file = "/home/andyvictory/slambook2/ch5/stereo/right.png";
修改CMakeLists文件如下:
find_package(Pangolin REQUIRED)
#链接OpenCV库
find_package(OpenCV REQUIRED)
include_directories(${OpenCV_INCLUDE_DIRS})add_executable(stereoVision stereoVision.cpp)
target_link_libraries(stereoVision ${OpenCV_LIBS} ${Pangolin_LIBRARIES})
编译运行即可。
如若出现报错:
Failed to load module "canberra-gtk-module"
在终端输入:
sudo apt-get install libcanberra-gtk-module
修改CMakeLists文件如下:
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})find_package( OpenCV 3.4.16 REQUIRED ) //这一步根据自己的版本来写
find_package(Pangolin REQUIRED)add_executable(joinMap joinMap.cpp)
target_link_libraries(joinMap ${OpenCV_LIBS} ${Pangolin_LIBRARIES} ${Sophus_INCLUDE_DIRS} fmt)
这一步主要是添加寻找OpenCV库和链接fmt库。
修改joinMap.cpp文件,修改21行(若行号不对请自行寻找)为:
ifstream fin("../pose.txt");
修改28行(若行号不对请自行寻找)为:
boost::format fmt("../%s/%d.%s"); //图像文件格式
编译运行成功: