Ubuntu18.04安装ORB_SLAM3

1.创建工作空间并编译

mkdir -p ~/catkin_ws/src
cd ~/catkin_ws/src
catkin_init_workspace
cd ~/catkin_ws/ 
catkin_make
source ~/catkin_ws/devel/setup.bash

2.安装依赖

sudo apt-get update

sudo apt-get install git cmake

sudo apt-get install libopencv-dev

sudo apt-get install libglew-dev
sudo apt-get install glew-utils

sudo apt-get install libboost-dev libboost-thread-dev libboost-filesystem-dev
sudo apt-get install libx11-dev libxmu-dev libglu1-mesa-dev libgl2ps-dev libxi-dev g++ libzip-dev libpng12-dev libcurl4-gnutls-dev libfontconfig1-dev libsqlite3-dev libglew*-dev libssl-dev

3.安装Panglin

git clone https://hub.fastgit.org/stevenlovegrove/Pangolin.git
cd Pangolin
./scripts/install_prerequisites.sh
mkdir build && cd build
cmake -DCPP11_NO_BOOST=1 ..
cmake --build .
sudo make install

4.安装Eigen 3

git clone https://github.com/eigenteam/eigen-git-mirror
cd eigen-git-mirror
mkdir build
cd build
cmake ..
sudo make install

5.编译安装ORB_SLAM3

git clone https://github.com/Lu-tju/ORB_SLAM3.git
cd ORB_SLAM3
chmod +x build.sh
./build.sh
#编译ros版本
cd ORB_SLAM3
chmod +x build_ros.sh
./build_ros.sh

gedit ~/.bashrc
export ROS_PACKAGE_PATH=${ROS_PACKAGE_PATH}:/home/fairy/catkin_ws/src/ORB_SLAM3/Examples/ROS
source ~/.bashrc

6.EuRoC 数据集测试

下载你想要的数据集,这里我下载的是Machine Hall 01的ASL Dateset Format,

解压之后将MH_01_easy修改为MH01即可。我是自己在编译后的ORB_SLAM3/Examples/ROS/ORB_SLAM3/路径下新建一个dateset的文件夹,里面再建一个名为MH01的文件夹,最后将下载好的数据集解压到MH01内。然后在进入到/catkin_ws/src/ORB_SLAM3下执行下面命令,即可实现

./Examples/Monocular/mono_euroc ./Vocabulary/ORBvoc.txt ~/catkin_ws/src/ORB_SLAM3/Examples/Monocular/EuRoC.yaml /home/fairy/catkin_ws/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3/dataset/MH01/ ./Examples/Monocular/EuRoC_TimeStamps/MH01.txt  dataset-MH01-mono

其中~/catkin_ws/src/ORB_SLAM3...是自己的工作空间路径,/home/fairy/catkin_ws/src/ORB_SLAM3/Examples/ROS/ORB_SLAM3/dataset/MH01/是自己数据集mavo存放的上一级路径

7.用摄像头进行测试

1.安装usb_cam

cd catkin_ws/src/
git clone https://github.com/bosch-ros-pkg/usb_cam.git usb_cam 
cd usb_cam/
mkdir build 
cd build 
cmake ..
make

 2.配置一些文件

cd catkin_ws/src/ORB_SLAM3/Examples/Monocular
sudo gedit myvideo.cpp

myvideo.cpp内容如下

//需要opencv库
#include 

//ORB_SLAM的系统接口
#include "System.h"

#include 
//计算时间
#include    
#include 

using namespace std;

//如果系统的路径不同,需要修改路径
string parameterFile = "./myvideo.yaml";
string vocFile = "./../../Vocabulary/ORBvoc.txt";

//视频文件,该示例中视频文件存放在/Workspace/src/ORB_SLAM3/Examples/Monocular下
string videoFile = "./video.mp4";

int main(int argc, char **argv){
	//声明ORB_SLAM3系统
	ORB_SLAM3::System SLAM(vocFile, parameterFile, ORB_SLAM3::System::MONOCULAR, true);
	
	//获取视频图像
	cv::VideoCapture cap(videoFile); //如果使用的是USB相机,将该参数修改成接口名称,如:0,1
	
	//记录系统时间
	auto start = chrono::system_clock::now();
	
	while(1){
		cv::Mat frame;
		cap >> frame;  //读取相机数据
		if(frame.data == nullptr)
			break;
		cv::Mat frame_resized;
		cv::resize(frame, frame_resized, cv::Size(960,540));//运行时显示的视频的尺寸
		
		auto now = chrono::system_clock::now();
		auto timestamp = chrono::duration_cast(now - start);
		SLAM.TrackMonocular(frame_resized, double(timestamp.count())/1000.0);
		cv::waitKey(30);
	}
	SLAM.Shutdown();
	return 0;
}

在复制一份.yaml文件,重命名为myvideo.yaml,内容如下

%YAML:1.0

#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
Camera.type: "PinHole"

# Camera calibration and distortion parameters (OpenCV) 
Camera.fx: 614.3472290039062
Camera.fy: 613.3615112304688
Camera.cx: 314.36767578125
Camera.cy: 239.8182830810547

Camera.k1: 0.0
Camera.k2: 0.0
Camera.p1: 0.0
Camera.p2: 0.0
Camera.k3: 0.0

# Camera frames per second 
Camera.fps: 30.0

# Color order of the images (0: BGR, 1: RGB. It is ignored if images are grayscale)
Camera.RGB: 1
# Camera resolution
Camera.width: 1920
Camera.height: 1080

#--------------------------------------------------------------------------------------------
# ORB Parameters
#--------------------------------------------------------------------------------------------

# ORB Extractor: Number of features per image
ORBextractor.nFeatures: 1000

# ORB Extractor: Scale factor between levels in the scale pyramid 	
ORBextractor.scaleFactor: 1.2

# ORB Extractor: Number of levels in the scale pyramid	
ORBextractor.nLevels: 8

# ORB Extractor: Fast threshold
# Image is divided in a grid. At each cell FAST are extracted imposing a minimum response.
# Firstly we impose iniThFAST. If no corners are detected we impose a lower value minThFAST
# You can lower these values if your images have low contrast			
ORBextractor.iniThFAST: 20
ORBextractor.minThFAST: 7

#--------------------------------------------------------------------------------------------
# Viewer Parameters
#--------------------------------------------------------------------------------------------
Viewer.KeyFrameSize: 0.05
Viewer.KeyFrameLineWidth: 5
Viewer.GraphLineWidth: 0.9
Viewer.PointSize:2
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3
Viewer.ViewpointX: 0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500

在/home/fairy/catkin_ws/src/ORB_SLAM3/CmakeLists.txt添加以下内容,添加的位置在set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR}/Examples/Monocular)后面,确保文件生成位置。

add_executable(myvideo Examples/Monocular/myvideo.cpp)
target_link_libraries(myvideo ${PROJECT_NAME})

3.编译运行

cd catkin_ws/
catkin_make

编译成功后,执行

cd src/ORB_SLAM3/
./build.sh

生成myvideo可执行文件后,打开终端运行roscore,然后进入到catkin_ws/src/ORB_SLAM3/Examples/Monocluar下执行

./myvideo

数据集下载链接

参考文章

参考文章

你可能感兴趣的:(Ubuntu,ROS,ORB_SLAM3,ubuntu,linux)