-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy pathmono_webcam.cc
More file actions
101 lines (81 loc) · 2.83 KB
/
mono_webcam.cc
File metadata and controls
101 lines (81 loc) · 2.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* This file is part of ORB-SLAM3
*
* Copyright (C) 2017-2021 Carlos Campos, Richard Elvira, Juan J. Gómez Rodríguez, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
* Copyright (C) 2014-2016 Raúl Mur-Artal, José M.M. Montiel and Juan D. Tardós, University of Zaragoza.
*
* ORB-SLAM3 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public
* License as published by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* ORB-SLAM3 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even
* the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License along with ORB-SLAM3.
* If not, see <http://www.gnu.org/licenses/>.
*/
#include <signal.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
#include <fstream>
#include <chrono>
#include <ctime>
#include <sstream>
#include <opencv2/core/core.hpp>
#include <opencv2/highgui.hpp>
#include <System.h>
using namespace std;
bool b_continue_session = true;
void exit_loop_handler(int s)
{
cout << "Finishing session" << endl;
b_continue_session = false;
}
int main(int argc, char **argv)
{
if (argc < 3 || argc > 4)
{
cerr << endl
<< "Usage: ./mono_webcam path_to_vocabulary path_to_settings (trajectory_file_name)" << endl;
return 1;
}
string file_name;
bool bFileName = false;
if (argc == 4)
{
file_name = string(argv[argc - 1]);
bFileName = true;
}
// Set video capture to interface 0 (default)
cv::VideoCapture cap(0);
if (!cap.isOpened()) {
std::cout << "Cannot open camera";
return 1;
}
cout.precision(17);
// Create SLAM system. It initializes all system threads and gets ready to process frames.
// ORB_SLAM3::System SLAM("../../Vocabulary/ORBvoc.txt", "webcam.yaml", ORB_SLAM3::System::MONOCULAR, true);
ORB_SLAM3::System SLAM(argv[1], argv[2], ORB_SLAM3::System::MONOCULAR, true);
float imageScale = SLAM.GetImageScale();
cv::Mat imCV;
double t_resize = 0.f;
double t_track = 0.f;
while (b_continue_session)
{
double timestamp_ms = chrono::duration_cast<chrono::milliseconds>(chrono::system_clock::now().time_since_epoch()).count();
cap >> imCV;
if (imageScale != 1.f)
{
int width = imCV.cols * imageScale;
int height = imCV.rows * imageScale;
cv::resize(imCV, imCV, cv::Size(width, height));
}
// Pass the image to the SLAM system
SLAM.TrackMonocular(imCV, timestamp_ms);
}
// Stop all threads
SLAM.Shutdown();
return 0;
}