myvideo.cpp
from 高博老師
#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 1 if you want to use USB camera.
// 記錄系統時間
auto start = chrono::system_clock::now();
while (1) {
cv::Mat frame;
cap >> frame; // 讀取相機資料
if ( frame.data == nullptr )
break;
// 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);
}
SLAM.Shutdown();
return 0;
}
将myvideo.cpp myvideo.mp4 myvideo.yaml放在ORB_SLAM2中
在CMakeLists.txt中添加
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${PROJECT_SOURCE_DIR})
add_executable(myvideo myvideo.cpp)
target_link_libraries(myvideo ${PROJECT_NAME})
cd build
cd ..
./myvideo
over~
官方的demo因為重點突出雜物少像素渣,跑起來更順暢一些