-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
134 lines (103 loc) · 2.93 KB
/
main.cpp
File metadata and controls
134 lines (103 loc) · 2.93 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#include <iostream>
#include <Eigen/Dense>
#include <stdexcept>
#include <pangolin/display/display.h>
#include <pangolin/display/view.h>
#include <pangolin/scene/scenehandler.h>
#include <pangolin/gl/gldraw.h>
#include <pangolin/utils/timer.h>
#include <opencv2/opencv.hpp>
#include "./frame.h"
#include "./camera_params.hpp"
int main( int argc, char *argv[] )
{
// Read command line arguments
double INPUT_f;
int INPUT_skip = 5;
std::string INPUT_vid_location;
// TO DO:
// Handle input correctly
if (argc == 4)
{
std::istringstream iss(argv[1]);
iss >> INPUT_f;
std::istringstream iss2(argv[2]);
iss2 >> INPUT_skip;
std::istringstream iss3(argv[3]);
iss3 >> INPUT_vid_location;
} else std::invalid_argument("Invalid number of command line arguments");
pangolin::CreateWindowAndBind("Main",1600,1000);
glEnable(GL_DEPTH_TEST);
// Define Projection and initial ModelView matrix
pangolin::OpenGlRenderState s_cam(
pangolin::ProjectionMatrix(1600,1000,680,680,800,500,0.2,100),
pangolin::ModelViewLookAt(0,4,2, 0,0,0, pangolin::AxisY)
);
// Object to hold all scene objects
pangolin::Renderable scene;
// Create Interactive View in window
pangolin::SceneHandler handler(scene,s_cam);
pangolin::View& d_cam = pangolin::CreateDisplay()
.SetBounds(0.0, 1.0, 0.0, 1.0, -1600.0f/1000.0f)
.SetHandler(&handler);
d_cam.SetDrawFunction([&](pangolin::View& view){
view.Activate(s_cam);
scene.Render();
});
// Open up video stream
cv::VideoCapture vid1(INPUT_vid_location);
// Safety check
if (!vid1.isOpened())
{
throw std::invalid_argument("Invalid input video stream");
return -1;
}
// Init camera/sensor config
// Grab one frame to check input image dims
cv::Mat initImg;
vid1 >> initImg;
double img_scale = 1;
if (initImg.cols > 960) img_scale = initImg.cols/960;
CameraParams<double> camera(
img_scale, initImg.cols, initImg.rows, INPUT_f
);
// Store 2 most recent frames for feature matching
std::queue<cv::Mat> vid_frames;
bool isVidBuff = true;
// Main program loop
while( !pangolin::ShouldQuit() )
{
// Clear screen and activate view to render into
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
if (isVidBuff)
{
cv::Mat video_frame;
int extra_skip = 0;
// Capture frame
vid1 >> video_frame;
// If SKIP > 0 skips extra frames
while( !video_frame.empty() && extra_skip < INPUT_skip)
{
vid1 >> video_frame;
extra_skip++;
}
// If video stream is finished stop reading it but allow for OpenGl loop
if ( video_frame.empty() )
{
isVidBuff = false;
continue;
}
// Push frame to the vector for use in "doFrame" function
vid_frames.push(video_frame);
}
// All the action happens inside
doFrame(scene, camera, vid_frames);
// Swap frames and Process Events
pangolin::FinishFrame();
// remove the previous frame
if (isVidBuff && vid_frames.size() > 1) vid_frames.pop();
}
vid1.release();
cv::waitKey(0);
return 0;
}