CV学习日志:Basalt使用总结

1.U2004安装
    (1)Basalt主页:https://vision.in.tum.de/research/vslam/basalt
    (2)Basalt源码:https://gitlab.com/VladyslavUsenko/basalt && https://gitlab.com/VladyslavUsenko/basalt-headers
    (3)Basalt文档:https://vladyslavusenko.gitlab.io/basalt-headers
    (4)DSCM主页:https://vision.in.tum.de/research/vslam/double-sphere
    (9)Readme.md中提供了官源安装和编译安装两种方式,这里采用编译安装的方式:
        1)解压源码到/root/app/basalt。
        2)执行scripts/install_deps.sh安装依赖。
        3)新建并终端进入/root/app/basalt/out执行cmake .. -DCMAKE_BUILD_TYPE=RelWithDebInfo和make -j4。
2.Win10安装
2.1下载源码
    (1)大致过程:下载源码重写CMakeLists.txt来编译,同时下载没有的第三库,主要是bz2和lz2。
    (2)下载Baslat:从https://gitlab.com/VladyslavUsenko/basalt下载解压到D:/app/basalt。
    (3)下载安装BZ2:从https://github.com/philr/bzip2-windows下载发布版并提取头文件和静态库到D:/app/basalt/thirdparty/bz2lz4。
    (4)下载安装LZ4:从https://github.com/lz4/lz4下载(发布版有问题)编译静态工程liblz4并复制到D:/app/basalt/thirdparty/bz2lz4。
    (5)管理已有的第三方库:删除OpenGV、CLI11、Pangolin,提取basalt-headers的纯头文件到指定位置。
2.2修改Basalt头文件
    (1)utils->sassert.h:用__FUNCTION__替换__PRETTY_FUNCTION__、用(x)替换__builtin_expect(x, 1)、注释__attribute__((noreturn))
    (2)utils->sophus_utils.hpp:添加#ifndef M_PI #define M_PI 3.1415926535897932384626433832795 #endif
    (3)camera->xxx_camera.hpp:替换所有private为public、重载project实现纯指针输入输出且三维坐标为三维。
    (4)camera->generic_camera.hpp:增加#include <cscv/ModelCamera.hpp>、增加public使内部类型能被外部使用、增加函数成员setParam、追加VarianT自定义模型: XXXCM
    (5)serialization->headers_serialization.h:定义宏CerealXXCM对所有XXXCM并使用之    
2.3修改Basalt主文件
    (1)批量操作:分别用uint8_t替换u_int8_t、用uint16_t替换u_int16_t、删除所有.git文件。
    (2)rosbag->lz4s.c:添加#ifdef min #undef min #undef max #endif
    (3)rosbag->console_bridge_export.h:删除__attribute__((visibility("hidden")))、用__declspec(dllexport)替换__attribute__((visibility("default")))、用__declspec(deprecated)替换__attribute__ ((__deprecated__))
    (4)apriltag->MathUtil.h:添加#ifndef M_PI #define M_PI 3.1415926535897932384626433832795 #endif
     (5)basalt->dataset_io_rosbag.h:添加#ifdef min #undef min #undef max #endif
    (6)basalt->dataset_io.cpp:需要进一步解决此问题,当前解决方案是添加以下代码
        #include "../../thirdparty/ros/ros_comm/tools/rosbag_storage/src/bag.cpp"
        #include "../../thirdparty/ros/ros_comm/tools/rosbag_storage/src/view.cpp"
        #include "../../thirdparty/ros/ros_comm/tools/rosbag_storage/src/message_instance.cpp"
    (7)basalt->marg_data_io.cpp:用std::string filename = p.path().filename().string()替换std::string filename = p.path().filename()
    (8)basalt->spline_linearize.h:注释comment #include <tbb/tbb_stddef.h>
    
    双目相机标定测试:进入D:/app/basalt/out执行basalt_calibrate --dataset-path ../data/dataset-calib-cam3_512_16.bag --dataset-type bag --aprilgrid ../data/aprilgrid_6x6.json --result-path ../data/dataset-calib-cam3_512_16 --cam-types ds ds   或   basalt_calibrate --dataset-path ../data/dataset-calib-cam3_512_16 --dataset-type euroc --aprilgrid ../data/aprilgrid_6x6.json --result-path ../data/dataset-calib-cam3_512_16/rst --cam-types ds ds
    IMU相机标定测试:进入D:/app/basalt/out执行basalt_calibrate_imu --dataset-path ../data/dataset-calib-imu1_512_16.bag --dataset-type bag --aprilgrid ../data/aprilgrid_6x6.json --result-path ../data/dataset-calib-imu1_512_16 --gyro-noise-std 0.000282 --accel-noise-std 0.016 --gyro-bias-std 0.0001 --accel-bias-std 0.001   或   basalt_calibrate_imu --dataset-path ../data/dataset-calib-imu1_512_16 --dataset-type bag --aprilgrid ../data/aprilgrid_6x6.json --result-path ../data/dataset-calib-imu1_512_16/rst --gyro-noise-std 0.000282 --accel-noise-std 0.016 --gyro-bias-std 0.0001 --accel-bias-std 0.001
    ▲:临时删除所有.gitignore后进行git add再恢复,否则有些文件无法加入。
3.编译脚本

  1 cmake_minimum_required(VERSION 3.10)
  2 project(basalt)
  3 
  4 set(CMAKE_CXX_STANDARD 17)
  5 set(CMAKE_CXX_STANDARD_REQUIRED ON)
  6 set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out/$<0:>)
  7 set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out/$<0:>)
  8 set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/out/$<0:>)
  9 add_compile_options(-MD /bigobj)
 10 set(CMAKE_SUPPRESS_REGENERATION ON)# not create ZERO_CHECK project for msbuild
 11 
 12 #1.Qt5
 13 #include_directories(D:/app/qt/5.9.9/msvc2015_64/include)
 14 #file(GLOB Qt5_LIBS LIST_DIRECTORIES false D:/app/qt/5.9.9/msvc2015_64/lib/Qt5*.lib) #QtRelease      #libGLESv2.lib and libGLESv2d.lib conflict with QGLViewer and pangolin
 15 #file(GLOB Qt5_LIBS_DBG LIST_DIRECTORIES false D:/app/qt/5.9.9/msvc2015_64/lib/Qt5*d.lib) #QtDebug   #Qt5Bootstrap.lib cause errors
 16 #list(REMOVE_ITEM Qt5_LIBS ${Qt5_LIBS_DBG} D:/app/qt/5.9.9/msvc2015_64/lib/Qt5Bootstrap.lib)#remove QtDebug and Qt5Bootstrap
 17 #list(APPEND Qt5_LIBS D:/app/qt/5.9.9/msvc2015_64/lib/Qt5Gamepad.lib D:/app/qt/5.9.9/msvc2015_64/lib/Qt53DQuickScene2D.lib) #add removed items
 18 #list(APPEND Qt5_LIBS glu32.lib opengl32.lib Ws2_32.lib)#add opengl by find_package
 19 #add_compile_definitions(QT_WIDGETS_LIB) #For some QtLibs
 20 
 21 #2.Eigen3 Gflags Glog Ceres Sophus CLI11 Spdlog Cereal
 22 include_directories(D:/app/eigen/out/install/include/eigen3)
 23 include_directories(D:/app/gflags/out/install/include)
 24 include_directories(D:/app/glog/out/install/include)
 25 include_directories(D:/app/ceres/out/install/include)#copy headers of Sophus&CLI11&Spdlog&Cereal here
 26 file(GLOB Gflags_LIBS LIST_DIRECTORIES false D:/app/gflags/out/install/lib/gflags*.lib)
 27 file(GLOB Glog_LIBS LIST_DIRECTORIES false D:/app/glog/out/install/lib/glog*.lib)
 28 set(Ceres_LIBS D:/app/ceres/out/install/lib/ceres.lib shlwapi.lib)#Add macros and shlwapi.lib by find_package(Ceres REQUIRED HINTS D:/app/ceres/out/install/CMake)
 29 add_compile_definitions(GFLAGS_DLL_DECLARE_FLAG= GFLAGS_DLL_DEFINE_FLAG= GLOG_NO_ABBREVIATED_SEVERITIES GOOGLE_GLOG_DLL_DECL= GFLAGS_IS_A_DLL=0)
 30 
 31 #3.TBB OpenCV
 32 include_directories(D:/app/tbb/include)
 33 include_directories(D:/app/opencv/out/install/include)
 34 file(GLOB TBB_LIBS LIST_DIRECTORIES false D:/app/tbb/lib/intel64/vc14/tbb*.lib)
 35 file(GLOB OpenCV_LIBS LIST_DIRECTORIES false D:/app/opencv/out/install/x64/vc16/lib/opencv*.lib)
 36 
 37 #4.ROS2 ROS2EX Webots      #For ROS2: some denpendencies must be found by find_package and all of them are located at ~/ros2/share
 38 #include_directories(D:/app/ros2/include D:/app/ros2ex/out/install/include)
 39 #include_directories(D:/app/webots/include/controller/cpp D:/app/webots/include/controller/c)
 40 #file(GLOB ROS2_LIBS LIST_DIRECTORIES false D:/app/ros2/lib/*.lib)
 41 #file(GLOB ROS2EX_LIBS LIST_DIRECTORIES false D:/app/ros2ex/out/install/lib/*.lib)
 42 #file(GLOB Webots_LIBS LIST_DIRECTORIES false D:/app/webots/lib/controller/*.lib)
 43 
 44 #5.Octomap OpenGV
 45 include_directories(D:/app/opengv/out/install/include)
 46 file(GLOB OpenGV_LIBS LIST_DIRECTORIES false D:/app/opengv/out/install/lib/*.lib)
 47 
 48 #6.Boost Pangolin(not used)
 49 include_directories(D:/app/boost)
 50 include_directories(D:/app/pangolin/out/install/include)
 51 file(GLOB Boost_LIBS LIST_DIRECTORIES false D:/app/boost/lib64-msvc-14.2/*-vc142-mt-x64-1_75.lib)
 52 set(Pangolin_LIBS opengl32.lib glu32.lib mf.lib mfplat.lib mfreadwrite.lib mfuuid.lib strmiids.lib
 53 D:/app/pangolin/out/install/lib/glew.lib
 54 D:/app/pangolin/out/install/lib/jpeg.lib
 55 D:/app/pangolin/out/install/lib/libpng16_static.lib
 56 D:/app/pangolin/out/install/lib/zlibstatic.lib
 57 D:/app/pangolin/out/install/lib/pangolin.lib)#from find_package(Pangolin)
 58 
 59 #7.BZ2LZ4
 60 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/bz2lz4)
 61 file(GLOB BZ2LZ4_LIBS LIST_DIRECTORIES false ${CMAKE_SOURCE_DIR}/thirdparty/bz2lz4/*.lib)
 62 
 63 #8.AllLibs
 64 set(ALL_LIBS ${Qt5_LIBS} ${Gflags_LIBS} ${Glog_LIBS} ${Ceres_LIBS}
 65     ${TBB_LIBS} ${OpenCV_LIBS} ${ROS2_LIBS} ${ROS2EX_LIBS} ${Webots_LIBS}
 66     ${Octomap_LIBS} ${OpenGV_LIBS})
 67 link_libraries(${ALL_LIBS} ${Boost_LIBS} ${Pangolin_LIBS} ${BZ2LZ4_LIBS})
 68 message("ALL_LIBS: ${ALL_LIBS}")
 69 
 70 #Rosbag(with Boost BZ2 LZ2 ???)
 71 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/include)
 72 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/console_bridge/include)
 73 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/roscpp_core/cpp_common/include)
 74 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/roscpp_core/rostime/include)
 75 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/roscpp_core/roscpp_serialization/include)
 76 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/roscpp_core/roscpp_traits/include)
 77 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/ros_comm/utilities/roslz4/include)
 78 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/ros/ros_comm/tools/rosbag_storage/include)
 79 file(GLOB CONSOLE_BRIDGE_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ros/console_bridge/src/*.cpp)
 80 file(GLOB CPP_COMMON_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ros/roscpp_core/cpp_common/src/*.cpp)
 81 file(GLOB ROSCPP_SERIALIZATION_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ros/roscpp_core/roscpp_serialization/src/*.cpp)
 82 file(GLOB ROSTIME_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ros/roscpp_core/rostime/src/*.cpp)
 83 file(GLOB ROSBAG_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ros/ros_comm/tools/rosbag_storage/src/*.cpp)
 84 file(GLOB ROSLZ4_SRCS ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/ros/ros_comm/utilities/roslz4/src/[a-z]*.c)
 85 add_library(aosbag STATIC ${ROSBAG_SRCS} ${ROSTIME_SRCS} ${CPP_COMMON_SRCS} ${ROSCPP_SERIALIZATION_SRCS} ${ROSLZ4_SRCS} ${CONSOLE_BRIDGE_SRCS} ${CMAKE_SOURCE_DIR}/CMakeLists.txt)
 86 
 87 #Apriltag(with OpenCV)
 88 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/apriltag/include)
 89 include_directories(${CMAKE_SOURCE_DIR}/thirdparty/apriltag/ethz_apriltag2/include)
 90 file(GLOB APRILTAG_SRCS LIST_DIRECTORIES false ${CMAKE_SOURCE_DIR}/thirdparty/apriltag/ethz_apriltag2/src/*.cc)
 91 add_library(apriltag STATIC ${APRILTAG_SRCS} ${CMAKE_SOURCE_DIR}/thirdparty/apriltag/src/apriltag.cpp)
 92 
 93 #Basalt
 94 include_directories(${CMAKE_SOURCE_DIR}/include)
 95 #include_directories(${CMAKE_SOURCE_DIR}/thirdparty/basalt-headers/include)#put into ceres installation
 96 #include_directories(${CMAKE_SOURCE_DIR}/thirdparty/basalt-headers/thirdparty/cereal/include)#put into ceres installation
 97 add_library(basalt STATIC
 98     ${CMAKE_SOURCE_DIR}/src/io/dataset_io.cpp
 99     ${CMAKE_SOURCE_DIR}/src/io/marg_data_io.cpp
100     ${CMAKE_SOURCE_DIR}/src/calibration/aprilgrid.cpp
101     ${CMAKE_SOURCE_DIR}/src/calibration/calibraiton_helper.cpp
102     ${CMAKE_SOURCE_DIR}/src/calibration/vignette.cpp
103     ${CMAKE_SOURCE_DIR}/src/utils/vio_config.cpp
104     ${CMAKE_SOURCE_DIR}/src/optical_flow/optical_flow.cpp
105     ${CMAKE_SOURCE_DIR}/src/vi_estimator/keypoint_vio.cpp
106     ${CMAKE_SOURCE_DIR}/src/vi_estimator/keypoint_vio_linearize.cpp
107     ${CMAKE_SOURCE_DIR}/src/vi_estimator/keypoint_vo.cpp
108     ${CMAKE_SOURCE_DIR}/src/vi_estimator/vio_estimator.cpp
109     ${CMAKE_SOURCE_DIR}/src/vi_estimator/ba_base.cpp
110     ${CMAKE_SOURCE_DIR}/src/vi_estimator/nfr_mapper.cpp
111     ${CMAKE_SOURCE_DIR}/src/vi_estimator/landmark_database.cpp
112     ${CMAKE_SOURCE_DIR}/src/utils/keypoints.cpp)
113 target_link_libraries(basalt aosbag apriltag)
114 
115 #CalibBinoCam
116 add_executable(basalt_calibrate src/calibrate.cpp src/calibration/cam_calib.cpp)
117 target_link_libraries(basalt_calibrate basalt)
118 
119 #CalibImuCam
120 add_executable(basalt_calibrate_imu src/calibrate_imu.cpp src/calibration/cam_imu_calib.cpp)
121 target_link_libraries(basalt_calibrate_imu basalt)
122 
123 #RunVIOSim
124 add_executable(basalt_vio_sim src/vio_sim.cpp)
125 target_link_libraries(basalt_vio_sim basalt)
126 
127 #RunMapperSim
128 add_executable(basalt_mapper_sim src/mapper_sim.cpp)
129 target_link_libraries(basalt_mapper_sim basalt)
130 
131 #RunMapperSimNaive
132 add_executable(basalt_mapper_sim_naive src/mapper_sim_naive.cpp)
133 target_link_libraries(basalt_mapper_sim_naive basalt)
134 
135 #RunMapper
136 add_executable(basalt_mapper src/mapper.cpp)
137 target_link_libraries(basalt_mapper basalt)
138 
139 #RunOptFlow
140 add_executable(basalt_opt_flow src/opt_flow.cpp)
141 target_link_libraries(basalt_opt_flow basalt)
142 
143 #RunVIO
144 add_executable(basalt_vio src/vio.cpp)
145 target_link_libraries(basalt_vio basalt)
146 
147 #RunTimeSync
148 add_executable(basalt_time_alignment src/time_alignment.cpp)
149 target_link_libraries(basalt_time_alignment basalt)
150 
151 #RunKittiEval
152 add_executable(basalt_kitti_eval src/kitti_eval.cpp)
153 
154 #Installation
155 install(TARGETS basalt_calibrate basalt_calibrate_imu basalt_vio_sim basalt_mapper_sim basalt_mapper_sim_naive basalt_mapper basalt_opt_flow basalt_vio basalt_kitti_eval basalt_time_alignment basalt
156   RUNTIME DESTINATION ${CMAKE_INSTALL_PREFIX}/bin
157   LIBRARY DESTINATION ${CMAKE_INSTALL_PREFIX}/lib
158   ARCHIVE DESTINATION ${CMAKE_INSTALL_PREFIX}/lib)
View Code
原文地址:https://www.cnblogs.com/dzyBK/p/14614649.html