forked from JakobEngel/dso_ros
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.cpp
247 lines (190 loc) · 5.55 KB
/
main.cpp
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/**
* This file is part of DSO.
*
* Copyright 2016 Technical University of Munich and Intel.
* Developed by Jakob Engel <engelj at in dot tum dot de>,
* for more information see <http://vision.in.tum.de/dso>.
* If you use this code, please cite the respective publications as
* listed on the above website.
*
* DSO 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.
*
* DSO 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 DSO. If not, see <http://www.gnu.org/licenses/>.
*/
#include <locale.h>
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include "util/settings.h"
#include "FullSystem/FullSystem.h"
#include "util/Undistort.h"
#include "IOWrapper/Pangolin/PangolinDSOViewer.h"
#include "IOWrapper/OutputWrapper/SampleOutputWrapper.h"
#include <ros/ros.h>
#include <sensor_msgs/image_encodings.h>
#include <sensor_msgs/Image.h>
#include <sensor_msgs/CameraInfo.h>
#include <geometry_msgs/PoseStamped.h>
#include "cv_bridge/cv_bridge.h"
std::string calib = "";
std::string vignetteFile = "";
std::string gammaFile = "";
std::string saveFile = "";
bool useSampleOutput=false;
using namespace dso;
void parseArgument(char* arg)
{
int option;
char buf[1000];
if(1==sscanf(arg,"sampleoutput=%d",&option))
{
if(option==1)
{
useSampleOutput = true;
printf("USING SAMPLE OUTPUT WRAPPER!\n");
}
return;
}
if(1==sscanf(arg,"quiet=%d",&option))
{
if(option==1)
{
setting_debugout_runquiet = true;
printf("QUIET MODE, I'll shut up!\n");
}
return;
}
if(1==sscanf(arg,"nolog=%d",&option))
{
if(option==1)
{
setting_logStuff = false;
printf("DISABLE LOGGING!\n");
}
return;
}
if(1==sscanf(arg,"nogui=%d",&option))
{
if(option==1)
{
disableAllDisplay = true;
printf("NO GUI!\n");
}
return;
}
if(1==sscanf(arg,"nomt=%d",&option))
{
if(option==1)
{
multiThreading = false;
printf("NO MultiThreading!\n");
}
return;
}
if(1==sscanf(arg,"calib=%s",buf))
{
calib = buf;
printf("loading calibration from %s!\n", calib.c_str());
return;
}
if(1==sscanf(arg,"vignette=%s",buf))
{
vignetteFile = buf;
printf("loading vignette from %s!\n", vignetteFile.c_str());
return;
}
if(1==sscanf(arg,"gamma=%s",buf))
{
gammaFile = buf;
printf("loading gammaCalib from %s!\n", gammaFile.c_str());
return;
}
if(1==sscanf(arg,"savefile=%s",buf))
{
saveFile = buf;
printf("saving to %s on finish!\n", saveFile.c_str());
return;
}
printf("could not parse argument \"%s\"!!\n", arg);
}
FullSystem* fullSystem = 0;
Undistort* undistorter = 0;
int frameID = 0;
void vidCb(const sensor_msgs::ImageConstPtr img)
{
cv_bridge::CvImagePtr cv_ptr = cv_bridge::toCvCopy(img, sensor_msgs::image_encodings::MONO8);
assert(cv_ptr->image.type() == CV_8U);
assert(cv_ptr->image.channels() == 1);
if(setting_fullResetRequested)
{
std::vector<IOWrap::Output3DWrapper*> wraps = fullSystem->outputWrapper;
delete fullSystem;
for(IOWrap::Output3DWrapper* ow : wraps) ow->reset();
fullSystem = new FullSystem();
fullSystem->linearizeOperation=false;
fullSystem->outputWrapper = wraps;
if(undistorter->photometricUndist != 0)
fullSystem->setGammaFunction(undistorter->photometricUndist->getG());
setting_fullResetRequested=false;
}
MinimalImageB minImg((int)cv_ptr->image.cols, (int)cv_ptr->image.rows,(unsigned char*)cv_ptr->image.data);
ImageAndExposure* undistImg = undistorter->undistort<unsigned char>(&minImg, 1,0, 1.0f);
undistImg->timestamp=img->header.stamp.toSec(); // relay the timestamp to dso
fullSystem->addActiveFrame(undistImg, frameID);
frameID++;
delete undistImg;
}
int main( int argc, char** argv )
{
ros::init(argc, argv, "dso_live");
for(int i=1; i<argc;i++) parseArgument(argv[i]);
setting_desiredImmatureDensity = 1000;
setting_desiredPointDensity = 1200;
setting_minFrames = 5;
setting_maxFrames = 7;
setting_maxOptIterations=4;
setting_minOptIterations=1;
setting_logStuff = false;
setting_kfGlobalWeight = 1.3;
printf("MODE WITH CALIBRATION, but without exposure times!\n");
setting_photometricCalibration = 2;
setting_affineOptModeA = 0;
setting_affineOptModeB = 0;
undistorter = Undistort::getUndistorterForFile(calib, gammaFile, vignetteFile);
setGlobalCalib(
(int)undistorter->getSize()[0],
(int)undistorter->getSize()[1],
undistorter->getK().cast<float>());
fullSystem = new FullSystem();
fullSystem->linearizeOperation=false;
if(!disableAllDisplay)
fullSystem->outputWrapper.push_back(new IOWrap::PangolinDSOViewer(
(int)undistorter->getSize()[0],
(int)undistorter->getSize()[1]));
if(useSampleOutput)
fullSystem->outputWrapper.push_back(new IOWrap::SampleOutputWrapper());
if(undistorter->photometricUndist != 0)
fullSystem->setGammaFunction(undistorter->photometricUndist->getG());
ros::NodeHandle nh;
ros::Subscriber imgSub = nh.subscribe("image", 1, &vidCb);
ros::spin();
fullSystem->printResult(saveFile);
for(IOWrap::Output3DWrapper* ow : fullSystem->outputWrapper)
{
ow->join();
delete ow;
}
delete undistorter;
delete fullSystem;
return 0;
}