把录制的视频放入ORB-SLAM3文件夹内,文件命名为:myvideo.mp4
在同一目录下添加myvideo.yaml、myvideo.cc
1.相机标定文件–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
2.在Cmakelists.txt文件中末尾添加对应代码
#生成调用myvideo.mp4 可执行文件
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
add_executable(myvideo myvideo.cc)
target_link_libraries(myvideo ${PROJECT_NAME})
3.添加myvideo.cc文件
//需要opencv库
#include <opencv2/opencv.hpp>
//ORB_SLAM的系统接口
#include "System.h"
#include <string>
//计算时间
#include <chrono>
#include <iostream>
using namespace std;
string parameterFile = "./myvideo.yaml";
//这里我输入的是绝对路径
string vocFile = "/home/hr/ORB_SLAM3/ORB_SLAM3-master/Vocabulary/ORBvoc.txt";
//视频文件,该示例中视频文件存放在/ORB_SLAM3/Examples/Monocular下
string videoFile = "./myvideo.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<chrono::milliseconds>(now - start);
SLAM.TrackMonocular(frame_resized, double(timestamp.count())/1000.0);
cv::waitKey(30);
}
SLAM.Shutdown();
return 0;
}
重新编译ORB-SLAM3 会出现myvideo执行文件
在此文件夹打开终端输入:./myvideo
即可运行视频文章来源地址https://www.toymoban.com/news/detail-421489.html
文章来源:https://www.toymoban.com/news/detail-421489.html
到了这里,关于ORB-SLAM3跑本地视频的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!