赞
踩
参考教程:https://blog.csdn.net/ykwjt/article/details/88090748
这篇教程中关于使用自己的视频以运行ORB SLAM2好像有点问题,和同学komorebi_fresh(https://me.csdn.net/weixin_44270815)花了点时间解决了
注意:在文件夹ORB_SLAM2中建立下面的myvideo myvideo.yaml myvideo.cpp文件,以及自己的视频,如下图,否则会出现错误
cd ORB_SLAM2 #ORB_SLAM2的路径要根据自己的路径,我的ORB_SLAM2是在ros的工作空间里
gedit myvideo.yaml
在新建的文件中输入下面的代码:
%YAML:1.0 #-------------------------------------------------------------------------------------------- # Camera Parameters. Adjust them! #-------------------------------------------------------------------------------------------- # Camera calibration and distortion parameters (OpenCV) Camera.fx: 500.0 Camera.fy: 500.0 Camera.cx: 320.0 Camera.cy: 240.0 Camera.k1: 0 Camera.k2: 0 Camera.p1: 0 Camera.p2: 0 Camera.k3: 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: 0 #-------------------------------------------------------------------------------------------- # 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: 10 ORBextractor.minThFAST: 5 #-------------------------------------------------------------------------------------------- # Viewer Parameters #-------------------------------------------------------------------------------------------- Viewer.KeyFrameSize: 0.05 Viewer.KeyFrameLineWidth: 1 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
gedit myvideo.cpp
在新建的文件中输入下面的代码:
#include <opencv2/opencv.hpp> #include "System.h" #include <string> #include <chrono> // for time stamp #include <iostream> using namespace std; // 参数文件与字典文件 // 如果你系统上的路径不同,请修改它 string parameterFile = "./myvideo.yaml"; string vocFile = "./Vocabulary/ORBvoc.txt"; // 视频文件 string videoFile = "./myvideo.mp4"; int main(int argc, char **argv) { // 声明 ORB-SLAM2 系统 ORB_SLAM2::System SLAM(vocFile, parameterFile, ORB_SLAM2::System::MONOCULAR, true); // 获取视频图像 cv::VideoCapture cap(videoFile); // change to 0 if you want to use USB camera. // 记录系统时间 auto start = chrono::system_clock::now(); while (1) { cv::Mat frame; cap >> frame; // 读取相机数据 if ( frame.data == nullptr ) continue; // rescale because image is too large cv::Mat frame_resized; cv::resize(frame, frame_resized, cv::Size(640,360)); 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); } return 0; }
打开文件夹ORB_SLAM2里的CMakeLists.txt添加下面的代码
#生成调用myvideo.mp4 可执行文件
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
add_executable(myvideo myvideo.cpp)
target_link_libraries(myvideo ${PROJECT_NAME})
cd ORB_SLAM2
mkdir build
cd build
cmake ..
make -j
cd ..
./myvideo #(执行)
之后对myvideo.cpp进行修改后都要再次编译才能运行。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。