Run the orb_slam3 monocular program directly with the notebook camera and no longer run the data set

Prerequisites:

Calibrate the camera (if you just want to run through the program, this step can be skipped, and you can go back and calibrate after the program runs through)

Ros1 noetic camera calibration_JT_BOT's Blog-CSDN Blog

Orb_slam3 has been installed, if not, please refer to my previous installation process

If you want to learn ORB_SLAM3, start with compiling. If you can't compile it, everything is a cloud._JT_BOT's Blog-CSDN Blog

1. Edit the yaml file (you can skip this step if you just want to run through the program, use the yaml file that comes with the program)

Find the calibrationdata file generated after camera calibration, there are 2 text files at the end of the file, my text file here is

ost.txt and ost.yaml, as shown below:

orb-slam3 directory structure, inside the main directory

Create a new folder cam_slam3 in ORB_SLAM3, and copy the calibration file ost.yaml into this folder.

Refer to TUM1.yaml to modify the format of ost.yaml.

Note: ORB Parameters and Viewer Parameters do not need to be modified

2.camera_matrix:
insert image description here

correspond:

# Camera calibration and distortion parameters (OpenCV)

Camera1.fx:

Camera1.fy:

Camera1.cx:

Camera1.cy:

distortion_coefficients: [k1 k2 p1 p2 k3]
corresponding to the parameter value. The ORB parameters and Viewer parameters remain unchanged.

Modified ost.yaml

%YAML:1.0

#--------------------------------------------------------------------------------------------
# Camera Parameters. Adjust them!
#--------------------------------------------------------------------------------------------
File.version: "1.0"

Camera.type: "PinHole"

# Camera calibration and distortion parameters (OpenCV) 
Camera1.fx: 621.19783
Camera1.fy: 624.29785
Camera1.cx: 327.35984
Camera1.cy: 238.12506

Camera1.k1: 0.112341
Camera1.k2: -0.170053
Camera1.p1: -0.004971
Camera1.p2: 0.003109
Camera1.k3: 0.000000

# Camera frames per second 
Camera.fps: 30

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

# Camera resolution
Camera.width: 640
Camera.height: 480

#--------------------------------------------------------------------------------------------
# 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: 1.0
Viewer.GraphLineWidth: 0.9
Viewer.PointSize: 2.0
Viewer.CameraSize: 0.08
Viewer.CameraLineWidth: 3.0
Viewer.ViewpointX: 0.0
Viewer.ViewpointY: -0.7
Viewer.ViewpointZ: -1.8
Viewer.ViewpointF: 500.0

Create new cam_slam3.cpp in cam_slam3

// cam_slam3.cpp
// 该文件将打开你电脑的摄像头,并将图像传递给ORB-SLAM3进行定位
 
// opencv
#include <opencv2/opencv.hpp>
 
// ORB-SLAM的系统接口
#include "System.h"
#include <string>
#include <chrono>   // for time stamp
#include <iostream>
 
using namespace std;
 
// 参数文件与字典文件
// 如果你系统上的路径不同,请修改它
string parameterFile = "../ost.yaml";//这个文件如果没有可以用程序里面的yaml文件代替,比如TUM1.yaml
string vocFile = "../../Vocabulary/ORBvoc.txt";
 
int main(int argc, char **argv) {
 
    // 声明 ORB-SLAM2 系统
    ORB_SLAM3::System SLAM(vocFile, parameterFile, ORB_SLAM3::System::MONOCULAR, true);
 
    // 获取相机图像代码
    cv::VideoCapture cap(0);    // change to 1 if you want to use USB camera.
 
    // 分辨率设为640x480
    cap.set(cv::CAP_PROP_FRAME_WIDTH, 640);;//设置采集视频的宽度
    cap.set(cv::CAP_PROP_FRAME_HEIGHT, 480);//设置采集视频的高度
 
    // 记录系统时间
    auto start = chrono::system_clock::now();
 
    while (1) {
        cv::Mat frame;
        cap >> frame;   // 读取相机数据
        auto now = chrono::system_clock::now();
        auto timestamp = chrono::duration_cast<chrono::milliseconds>(now - start);
        SLAM.TrackMonocular(frame, double(timestamp.count())/1000.0);
    }
 
    return 0;
}

CMakeLists.txt

# CMakeLists.txt
cmake_minimum_required(VERSION 2.8)
project(cam_slam3)
find_package(OpenCV 4 REQUIRED) #opencv根据版本填写版本号
#包含头文件
include_directories(${OPENCV_INCLUDE_DIRS} 
#非标准头文件包含写法,根据编译报错用: sudo find / -name System.h 搜每一个缺少的头文件路径添加在下面
~/ORB_SLAM3/include   
~/ORB_SLAM3
/usr/include/eigen3
~/ORB_SLAM3/include/CameraModels
)  
#生成可执行文件
add_executable(cam_slam3 cam_slam3.cpp)  
#链接库文件
target_link_libraries(cam_slam3 ${OpenCV_LIBS} 
#非标准的链接库文件写法,根据编译报错用:sudo find / -name libpangolin.so 搜缺少的库文件
#按绝对路径添加缺少的库文件
/usr/local/lib/libpangolin.so
/lib/x86_64-linux-gnu/libOpenGL.so.0
/lib/x86_64-linux-gnu/libGLEW.so.2.1
~/ORB_SLAM3/lib/libORB_SLAM3.so

)

file structure

 Compile:

cd ORB_SLAM3/cam_slam3
mkdir build
cd build
cmake ..
make

 

 The compilation is complete./cam_slam3 Run the monocular program

 Seeing this image indicates that the operation was successful.

The difficulty of this implementation lies in compiling. You need to use sudo find / -name file name to search for missing header files and library files through compiling errors, and continuously adjust CMakeLists.txt until success.

reference:

USB camera runs ORB-SLAM2_Run slam2 with barrage usb camera_Hoshino Dawn's Blog-CSDN Blog

Guess you like

Origin blog.csdn.net/m0_73694897/article/details/130391045