解决ORB-SLAM在 ubuntu16 ros-kinetic下catkin_make 编译方式

文章目录

    • 写在前面
    • 安装依赖
    • 下载ORB-SLAM
    • 将之前的ros_build编译方式改为catkin_make方式
      • 修改CmakeLists.txt文件
      • 添加package.xml文件
    • 修改几行文件

写在前面

ORB-SLAM源文件是基于ROS 发布的软件,使用的编译方式是ros_build, 这样不便于工程的维护,也不便于与其他软件包的结合,所以本文提出方法,将其改为ubuntu16 ros-kinetic下catkin_make 编译方式,具体方式如下所示

安装依赖

  • 多线程 Boost library : launch the different threads of our SLAM system.
    sudo apt-get install libboost-all-dev

  • 图像处理 OpenCV library : manipulate images and features

  • 图优化 g2o : use a modified version of g2o to perform optimizations(g2o依赖于Eigen库)
    sudo apt-get install libeigen3-dev

  • 回环检测 DBoW2 : use of some components of the DBoW2 and DLib library for place recognition and feature matching

下载ORB-SLAM

  • git clone到 ros-workspace的src目录下
  • 将名字和工程名都改为小写字母(rospack 名称不支持大写)

将之前的ros_build编译方式改为catkin_make方式

修改CmakeLists.txt文件

cmake_minimum_required(VERSION 2.8.3)
project(orb-slam)


# include($ENV{ROS_ROOT}/core/rosbuild/rosbuild.cmake)
# rosbuild_init()
# IF(NOT ROS_BUILD_TYPE)
#   SET(ROS_BUILD_TYPE Release)
# ENDIF()
# MESSAGE("Build type: " ${ROS_BUILD_TYPE})


set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS}  -Wall  -O3 -march=native ")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall  -O3 -march=native")
set(CMAKE_BUILD_TYPE "Release")
set(CMAKE_CXX_FLAGS "-std=c++11")
set(CMAKE_CXX_FLAGS_RELEASE "-O3 -Wall -g")

## 生成的可执行文件在工程的 bin目录下
set(EXECUTABLE_OUTPUT_PATH ${PROJECT_SOURCE_DIR}/bin)

LIST(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)

## 依赖的ROS
find_package(catkin REQUIRED COMPONENTS
    roscpp
    std_msgs
    sensor_msgs
    tf
    image_transport
    cv_bridge
    )

find_package(OpenCV 3.1 REQUIRED)
find_package(Eigen3 REQUIRED)

catkin_package()

include_directories(
    ${catkin_INCLUDE_DIRS}
    ${PROJECT_SOURCE_DIR}/include
    )

include_directories(
  ${catkin_INCLUDE_DIRS}  
  ${PROJECT_SOURCE_DIR}
  ${EIGEN3_INCLUDE_DIR}
)

## 编译生成可执行文件 
# rosbuild_add_executable(${PROJECT_NAME}
add_executable( ${PROJECT_NAME}
src/main.cc
src/Tracking.cc
src/LocalMapping.cc
src/LoopClosing.cc
src/ORBextractor.cc
src/ORBmatcher.cc
src/FramePublisher.cc
src/Converter.cc
src/MapPoint.cc
src/KeyFrame.cc
src/Map.cc
src/MapPublisher.cc
src/Optimizer.cc
src/PnPsolver.cc
src/Frame.cc
src/KeyFrameDatabase.cc
src/Sim3Solver.cc
src/Initializer.cc
)
# rosbuild_add_boost_directories()
# rosbuild_link_boost(${PROJECT_NAME} thread)

target_link_libraries(${PROJECT_NAME}
${catkin_LIBRARIES}
${OpenCV_LIBS}
${EIGEN3_LIBS}
${PROJECT_SOURCE_DIR}/Thirdparty/DBoW2/lib/libDBoW2.so
${PROJECT_SOURCE_DIR}/Thirdparty/g2o/lib/libg2o.so
)


添加package.xml文件



  orb-slam
  0.0.0
  The ORB-SLAM package

   
  
  
  dvorak


  
  
  
  TODO

  
  
  
  
  
  
  
  
  
  
  
  catkin
  roscpp
  std_msgs
  sensor_msgs
  image_transport
  cv_bridge

  roscpp
  std_msgs
  sensor_msgs
  image_transport
  cv_bridge
  


  
  
    
    

    

  


修改几行文件

src/ORBextractor.cc 添加头文件
#include
#include

Thirdparty/g2o/g2o/solvers/linea_solver_eigen.h 修改
// typedef Eigen::PermutationMatrixSparseMatrix::Index> PermutationMatrix;
typedef Eigen::PermutationMatrixint> PermutationMatrix;

至此,就可以使用catkin_make 编译ORB-SLAM了

你可能感兴趣的:(视觉SLAM实战进阶开发)