Slam Lecture 14: Solving some Problems in Code Debugging

        I recently watched Slam Lecture 14, and it took me a long time to configure the code environment. Now there are many problems such as inconsistent library versions during operation. I will record them here. Will be updated:

Table of contents

1. Current configuration version

2. General solutions to some error reports

2.1  Pangolin:'xxxx' has not been declared

2.2 opencv: 'cv::xxxx' undefined reference

3. The general process of running the code

4. Partial operation

ch2 code run

ch3 code run

ch4 code running

ch5 code running

4.5.1 imageBasics running

4.5.2 rgbd operation

4.5.3 stereo operation

ch6 code running

ch7 code running

ch8 code running

ch9 code running

ch10 code running

ch11 code running

ch12 code running


1. Current configuration version

        1.own3.4.0

        2.Pangolin

        3.fmt8.1.1

        4.ceres

        5.g2o

        6. Dormitory

        7.DBoW3

        8.camke3.22.1

        The ones currently downloaded are the latest version, so there are many problems in the code, and some compatibility issues have not yet been resolved. The relevant parts that are prone to problems are installed in:

Ubuntu upgrade eigen to 3.4.0_Qianmengyu 11's blog-CSDN blog_eigen upgrade

Ubuntu upgrade cmake version_Qianmengyu 11's blog-CSDN blog_ubuntu upgrade cmake

Installing Sophus on ubuntu_Qianmengyu 11's blog-CSDN blog_sophus ubuntu

Installing the Pangolin library on ubuntu16.04_Qianmengyu 11's blog-CSDN blog

Ubuntu16.04 Verifies Pangolin Installation Successful_Qianmengyu 11’s Blog-CSDN Blog

Installing the ceres-solver library on ubuntu_Qianmengyu 11's blog-CSDN blog

Ubuntu16.04 C++ installation opencv tutorial_Qianmengyu 11's blog-CSDN blog


2. General solutions to some error reports

2.1  Pangolin:'xxxx' has not been declared

        Error reported:

error: ‘std::function’ has not been declared
 inline std::istream& operator>>(std::istream& /*is*/, std::function<Ret(Arg)>& 
                                                            ^
/usr/local/include/pangolin/utils/type_convert.h:58:68: error: expected ‘,’ or ‘...’ before ‘<’ token
 inline std::istream& operator>>(std::istream& /*is*/, std::function<Ret(Arg)>& 
                                                                    ^
/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<Ret(A
                                                                  ^
/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<Ret(Arg)>&
                                                                     ^
/usr/local/include/pangolin/utils/type_convert.h:65:60: error: ‘std::function’ has not been declared
 

        Solution: Add C++ standard judgment to CmakeLists.txt (many adding 1 line are not suitable):

# 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()

2.2 opencv: 'cv::xxxx' undefined reference

        Error reported:

CMakeFiles/joinMap.dir/joinMap.o: In function 'main':
joinMap.cpp:(.text+0x169): Undefined reference to 'cv::imread(cv::String const&, int)'
joinMap. cpp:(.text+0x240): undefined reference to 'cv::imread(cv::String const&, int)'
CMakeFiles/joinMap.dir/joinMap.o: in function 'cv::String::~String' ()' in:
joinMap.cpp: (.text._ZN2cv6StringD2Ev[_ZN2cv6StringD5Ev]+0x14): undefined reference to 'cv::String::deallocate()'
CMakeFiles/joinMap.dir/joinMap.o: in function ' In cv::String::operator=(cv::String const&)':
joinMap.cpp:(.text._ZN2cv6StringaSERKS0_[_ZN2cv6StringaSERKS0_]+0x28): undefined reference to 'cv::String::deallocate()'
CMakeFiles/joinMap.dir/joinMap.o: In function 'cv::Mat::Mat(cv::Mat const&)': joinMap.cpp
:(.text._ZN2cv3MatC2ERKS0_[_ZN2cv3MatC5ERKS0_]+0x182): For 'cv: :Mat::copySize(cv::Mat const&)' undefined reference
CMakeFiles/joinMap.dir/joinMap.o: In function 'cv::Mat::~Mat()':
joinMap.cpp:(.text._ZN2cv3MatD2Ev[_ZN2cv3MatD5Ev]+0x39): For 'cv::fastFree(void *)' undefined reference
CMakeFiles/joinMap.dir/joinMap.o: in function 'cv::Mat::release()':
joinMap.cpp:(.text._ZN2cv3Mat7releaseEv[_ZN2cv3Mat7releaseEv]+0x4b): right cv::Mat::deallocate()' undefined reference
CMakeFiles/joinMap.dir/joinMap.o: in function 'cv::String::String(std::__cxx11::basic_string<char, std::char_traits< char>, std::allocator<char> > const&)':
joinMap.cpp:(.text._ZN2cv6StringC2ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE[_ZN2cv6StringC5ERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEE ]+0x5d): undefined reference to 'cv::String::allocate(unsigned long)'
        

        Solution: Select the version and add specified opencv3 in CmakeLists.txt

        Note: This must be added in front of the target_link_libraries(xxxx ${OpenCV_LIBS} ${Pangolin_LIBRARIES}) command! ! ! Otherwise, an error will still be reported

# opencv3
find_package(OpenCV 3.0.0 REQUIRED)


3. The general process of running the code

        To be neater, enter a folder (with cpp and CmakeLists.txt), first create the build folder, cmake, etc. inside:

mkdir build
cd build
cmake ..
make

        A file without a suffix will be generated afterwards: If you do not need to pass in pictures, etc., directly ./execute the file:

./文件名

        If you need to pass in pictures, etc., you need to return to the previous folder (otherwise the pictures cannot be found in the build folder).

cd ..
./build/文件名 可能需要的图片名


4. Partial operation

        The problem with Sophus has not been solved yet, and the code may need to be changed. Anyone with ideas is welcome to discuss it.

        The incompatibility of g2o is not resolved


ch2 code run

        none.

ch3 code run

        None yet

ch4 code running

        None yet

ch5 code running

4.5.1 imageBasics running

        This is relatively smooth, just press 3 in front to go.

mkdir build
cd build
cmake ..
make

        Then come out, because you need to pass in the image file:

cd ..
./build/imageBasics ubuntu.png

        To de-distort the code, you need to remove the comments in CmakeLists.txt, and then continue with the previous cmake and make set:

 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})

        Then come out and import the picture:

cd ..
./build/undistortImage distorted.png

4.5.2 rgbd operation

        You need to consider the incompatibility of Pangolin and the problems of both opencv3 and 4: Add two blocks to CmakeLists.txt in three steps:

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()

        After that, use a set of cmake, run it after building (because you need to call the folder)

mkdir build
cd build
cmake ..
make

​
cd ..
./build/joinMap

4.5.3 stereo operation

        As before, consider the incompatibility of Pangolin and the problems of opencv3 and 4: Add two blocks to CmakeLists.txt in three steps: note that opencv must be in front of 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()

        Then continue with the terminal command line:

mkdir build
cd build
cmake ..
make

​
cd ..
./build/stereoVision

ch6 code running

        There are not many problems with this. You don’t need to change CmakeLists.txt and just cmake a set:

mkdir build
cd build
cmake ..
make

​
cd ..
./build/ceresCurveFitting
./build/gaussNewton

        But the g2o has not been adjusted yet.

ch7 code running

        Currently, pose_estimation_3d2d.cpp and pose_estimation_3d3d.cpp of g2o and Sophus are not running. No need to change 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

        Just enter the next four runs separately.

ch8 code running

ch9 code running

ch10 code running

ch11 code running

ch12 code running

Guess you like

Origin blog.csdn.net/weixin_43907136/article/details/128134369