最近看slam十四讲,代码环境配了半天配差不多,现在运行中间还有很多库版本不一致等各种问题,这里记录一下。会更新:
目录
一、目前配置版本
二、一些报错的通用解决
2.1 Pangolin:'xxxx' has not been declared
2.2 opencv:'cv::xxxx'未定义的引用
三、代码运行大致流程
四、部分运行
ch2代码运行
ch3代码运行
ch4代码运行
ch5代码运行
4.5.1 imageBasics运行
4.5.2 rgbd运行
4.5.3 stereo运行
ch6代码运行
ch7代码运行
ch8代码运行
ch9代码运行
ch10代码运行
ch11代码运行
ch12代码运行
1.eigen3.4.0
2.Pangolin
3.fmt8.1.1
4.ceres
5.g2o
6.Sophus
7.DBoW3
8.camke3.22.1
目前下的都是现在最新版本,因此代码中出了很多问题,有一些兼容问题还没有解决。相关部分容易出问题的安装在:
ubuntu升级eigen到3.4.0_浅梦语11的博客-CSDN博客_eigen升级
Ubuntu升级cmake版本_浅梦语11的博客-CSDN博客_ubuntu 升级cmake
ubuntu安装Sophus_浅梦语11的博客-CSDN博客_sophus ubuntu
ubuntu16.04安装Pangolin库_浅梦语11的博客-CSDN博客
ubuntu16.04验证Pangolin安装成功_浅梦语11的博客-CSDN博客
ubuntu安装ceres-solver库_浅梦语11的博客-CSDN博客
Ubuntu16.04 C++安装opencv教程_浅梦语11的博客-CSDN博客
报错:
error: ‘std::function’ has not been declared
inline std::istream& operator>>(std::istream& /*is*/, std::function
^
/usr/local/include/pangolin/utils/type_convert.h:58:68: error: expected ‘,’ or ‘...’ before ‘<’ token
inline std::istream& operator>>(std::istream& /*is*/, std::function
^
/usr/local/include/pangolin/utils/type_convert.h:62:66: error: ‘function’ in namespace ‘std’ does not name a template type
inline std::ostream& operator<<(std::ostream& /*os*/, const std::function
/usr/local/include/pangolin/utils/type_convert.h:62:74: error: expected ‘,’ or ‘...’ before ‘<’ token
e std::ostream& operator<<(std::ostream& /*os*/, const std::function
^
/usr/local/include/pangolin/utils/type_convert.h:65:60: error: ‘std::function’ has not been declared
解决:在CmakeLists.txt中加入C++标准判断(很多加1行的不太行):
# Check C++11 or C++0x support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DCOMPILEDWITHC11)
message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
add_definitions(-DCOMPILEDWITHC0X)
message(STATUS "Using flag -std=c++0x.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
报错:
CMakeFiles/joinMap.dir/joinMap.o:在函数‘main’中:
joinMap.cpp:(.text+0x169):对‘cv::imread(cv::String const&, int)’未定义的引用
joinMap.cpp:(.text+0x240):对‘cv::imread(cv::String const&, int)’未定义的引用
CMakeFiles/joinMap.dir/joinMap.o:在函数‘cv::String::~String()’中:
joinMap.cpp:(.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14):对‘cv::String::deallocate()’未定义的引用
CMakeFiles/joinMap.dir/joinMap.o:在函数‘cv::String::operator=(cv::String const&)’中:
joinMap.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28):对‘cv::String::deallocate()’未定义的引用
CMakeFiles/joinMap.dir/joinMap.o:在函数‘cv::Mat::Mat(cv::Mat const&)’中:
joinMap.cpp:(.text._ZN2cv3MatC2ERKS0_[_ZN2cv3MatC5ERKS0_]+0x182):对‘cv::Mat::copySize(cv::Mat const&)’未定义的引用
CMakeFiles/joinMap.dir/joinMap.o:在函数‘cv::Mat::~Mat()’中:
joinMap.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39):对‘cv::fastFree(void*)’未定义的引用
CMakeFiles/joinMap.dir/joinMap.o:在函数‘cv::Mat::release()’中:
joinMap.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b):对‘cv::Mat::deallocate()’未定义的引用
CMakeFiles/joinMap.dir/joinMap.o:在函数‘cv::String::String(std::__cxx11::basic_string
joinMap.cpp:(.text._ZN2cv6StringC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN2cv6StringC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE]+0x5d):对‘cv::String::allocate(unsigned long)’未定义的引用
解决:选定版本,在CmakeLists.txt中加入指定opencv3
注意:这个要加在target_link_libraries(xxxx ${OpenCV_LIBS} ${Pangolin_LIBRARIES})命令前面!!!要不然还是报错
# opencv3
find_package(OpenCV 3.0.0 REQUIRED)
为了整洁点,进入某个文件夹(有cpp和CmakeLists.txt的),先创建build文件夹,在里面cmake等:
mkdir build
cd build
cmake ..
make
之后会产生一个没有后缀的文件:如果不需要传入图片等,直接./执行文件:
./文件名
如果需要传入图片等,需要返回上一文件夹(要不build文件夹内找不到图片)。
cd ..
./build/文件名 可能需要的图片名
Sophus的问题还没解决,没准要改代码,有思路的欢迎讨论。
g2o的不兼容未解决
无。
暂无
暂无
这个比较顺利,直接前面按3的走。
mkdir build
cd build
cmake ..
make
之后出来,因为需要传入图片文件:
cd ..
./build/imageBasics ubuntu.png
去畸变的代码需要将CmakeLists.txt的注释去掉,之后继续前面的cmake,make一套:
CmakeLists.txt
cmake_minimum_required(VERSION 2.8)
# 解决加上C++版本之后,未定义引用问题
find_package(OpenCV REQUIRED)
message(STATUS "OpenCV library status:")
message(STATUS " version: ${OpenCV_VERSION}")
message(STATUS " libraries: ${OpenCV_LIBS}")
message(STATUS " include path: ${OpenCV_INCLUDE_DIRS}")
if(CMAKE_VERSION VERSION_LESS "2.8.11")
# Add OpenCV headers location to your include paths
include_directories(${OpenCV_INCLUDE_DIRS})
endif()
#SET(CMAKE_CXX_FLAGS "-std=c++0x")
SET( CMAKE_CXX_FLAGS "-std=c++11 -O3")
add_executable(imageBasics imageBasics.cpp)
# 链接OpenCV库
target_link_libraries(imageBasics ${OpenCV_LIBS})
add_executable(undistortImage undistortImage.cpp)
# 链接OpenCV库
target_link_libraries(undistortImage ${OpenCV_LIBS})
之后出来传入图片:
cd ..
./build/undistortImage distorted.png
需要考虑Pangolin不兼容和opencv3和4都有的问题:CmakeLists.txt按三的步骤加两块:
find_package(Sophus REQUIRED)
include_directories(${Sophus_INCLUDE_DIRS})
find_package(Pangolin REQUIRED)
# opencv3
find_package(OpenCV 3.0.0 REQUIRED)
add_executable(joinMap joinMap.cpp)
target_link_libraries(joinMap ${OpenCV_LIBS} ${Pangolin_LIBRARIES})
# Check C++11 or C++0x support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DCOMPILEDWITHC11)
message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
add_definitions(-DCOMPILEDWITHC0X)
message(STATUS "Using flag -std=c++0x.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
之后,cmake一套,出来build后运行(因为需要调用文件夹)
mkdir build
cd build
cmake ..
make
cd ..
./build/joinMap
和前面一样,考虑Pangolin不兼容和opencv3和4都有的问题:CmakeLists.txt按三的步骤加两块:注意opencv的必须在target_link_libraries(stereoVision ${OpenCV_LIBS} ${Pangolin_LIBRARIES})前面:
CmakeLists.txt
find_package(Pangolin REQUIRED)
# opencv3
find_package(OpenCV 3.4.11 REQUIRED)
add_executable(stereoVision stereoVision.cpp)
target_link_libraries(stereoVision ${OpenCV_LIBS} ${Pangolin_LIBRARIES})
# Check C++11 or C++0x support
include(CheckCXXCompilerFlag)
CHECK_CXX_COMPILER_FLAG("-std=c++11" COMPILER_SUPPORTS_CXX11)
CHECK_CXX_COMPILER_FLAG("-std=c++0x" COMPILER_SUPPORTS_CXX0X)
if(COMPILER_SUPPORTS_CXX11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11")
add_definitions(-DCOMPILEDWITHC11)
message(STATUS "Using flag -std=c++11.")
elseif(COMPILER_SUPPORTS_CXX0X)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++0x")
add_definitions(-DCOMPILEDWITHC0X)
message(STATUS "Using flag -std=c++0x.")
else()
message(FATAL_ERROR "The compiler ${CMAKE_CXX_COMPILER} has no C++11 support. Please use a different C++ compiler.")
endif()
之后继续终端命令行:
mkdir build
cd build
cmake ..
make
cd ..
./build/stereoVision
这个问题不多,不用改CmakeLists.txt直接cmake一套:
mkdir build
cd build
cmake ..
make
cd ..
./build/ceresCurveFitting
./build/gaussNewton
但是g2o的还没调好
目前也是有g2o和Sophus的pose_estimation_3d2d.cpp和pose_estimation_3d3d.cpp没有运行。不用改CmakeLists.txt:
mkdir build
cd build
cmake ..
make
cd ..
./build/orb_cv 1.png 2.png
./build/orb_self
./build/pose_estimation_2d2d 1.png 2.png
./build/triangulation 1.png 2.png
后面四个运行分别输入就行。