-
Notifications
You must be signed in to change notification settings - Fork 204
Expand file tree
/
Copy pathSampleOutputWrapper.h
More file actions
237 lines (190 loc) · 7.69 KB
/
SampleOutputWrapper.h
File metadata and controls
237 lines (190 loc) · 7.69 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
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
/**
* 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/>.
*/
#pragma once
#include "boost/thread.hpp"
#include "util/MinimalImage.h"
#include "IOWrapper/Output3DWrapper.h"
#include "FullSystem/HessianBlocks.h"
#include "util/FrameShell.h"
namespace dso
{
class FrameHessian;
class CalibHessian;
class FrameShell;
namespace IOWrap
{
class SampleOutputWrapper : public Output3DWrapper
{
public:
inline SampleOutputWrapper()
{
numPCL = 0;
isSavePCL = true;
isPCLfileClose = false;
pclFile.open(strTmpFileName);
printf("OUT: Created SampleOutputWrapper\n");
}
virtual ~SampleOutputWrapper()
{
if (pclFile.is_open())
{
pclFile.close();
}
printf("OUT: Destroyed SampleOutputWrapper\n");
}
virtual void publishGraph(const std::map<uint64_t, Eigen::Vector2i, std::less<uint64_t>, Eigen::aligned_allocator<std::pair<const uint64_t, Eigen::Vector2i>>> &connectivity) override
{
printf("OUT: got graph with %d edges\n", (int)connectivity.size());
int maxWrite = 5;
for(const std::pair<uint64_t,Eigen::Vector2i> &p : connectivity)
{
int idHost = p.first>>32;
int idTarget = p.first & ((uint64_t)0xFFFFFFFF);
printf("OUT: Example Edge %d -> %d has %d active and %d marg residuals\n", idHost, idTarget, p.second[0], p.second[1]);
maxWrite--;
if(maxWrite==0) break;
}
}
virtual void publishKeyframes( std::vector<FrameHessian*> &frames, bool final, CalibHessian* HCalib) override
{
/*for(FrameHessian* f : frames)
{
printf("OUT: KF %d (%s) (id %d, tme %f): %d active, %d marginalized, %d immature points. CameraToWorld:\n",
f->frameID,
final ? "final" : "non-final",
f->shell->incoming_id,
f->shell->timestamp,
(int)f->pointHessians.size(), (int)f->pointHessiansMarginalized.size(), (int)f->immaturePoints.size());
std::cout << f->shell->camToWorld.matrix3x4() << "\n";
int maxWrite = 5;
for(PointHessian* p : f->pointHessians)
{
printf("OUT: Example Point x=%.1f, y=%.1f, idepth=%f, idepth std.dev. %f, %d inlier-residuals\n",
p->u, p->v, p->idepth_scaled, sqrt(1.0f / p->idepth_hessian), p->numGoodResiduals );
maxWrite--;
if(maxWrite==0) break;
}
}
*/
float fx, fy, cx, cy;
float fxi, fyi, cxi, cyi;
//float colorIntensity = 1.0f;
fx = HCalib->fxl();
fy = HCalib->fyl();
cx = HCalib->cxl();
cy = HCalib->cyl();
fxi = 1 / fx;
fyi = 1 / fy;
cxi = -cx / fx;
cyi = -cy / fy;
if (final)
{
for (FrameHessian* f : frames)
{
if (f->shell->poseValid)
{
auto const& m = f->shell->camToWorld.matrix3x4();
// use only marginalized points.
auto const& points = f->pointHessiansMarginalized;
for (auto const* p : points)
{
float depth = 1.0f / p->idepth;
auto const x = (p->u * fxi + cxi) * depth;
auto const y = (p->v * fyi + cyi) * depth;
auto const z = depth * (1 + 2 * fxi);
Eigen::Vector4d camPoint(x, y, z, 1.f);
Eigen::Vector3d worldPoint = m * camPoint;
if (isSavePCL && pclFile.is_open())
{
isWritePCL = true;
pclFile << worldPoint[0] << " " << worldPoint[1] << " " << worldPoint[2] << "\n";
printf("[%d] Point Cloud Coordinate> X: %.2f, Y: %.2f, Z: %.2f\n",
numPCL,
worldPoint[0],
worldPoint[1],
worldPoint[2]);
numPCL++;
isWritePCL = false;
}
else
{
if (!isPCLfileClose)
{
if (pclFile.is_open())
{
pclFile.flush();
pclFile.close();
isPCLfileClose = true;
}
}
}
}
}
}
}
}
virtual void publishCamPose(FrameShell* frame, CalibHessian* HCalib) override
{
printf("OUT: Current Frame %d (time %f, internal ID %d). CameraToWorld:\n",
frame->incoming_id,
frame->timestamp,
frame->id);
std::cout << frame->camToWorld.matrix3x4() << "\n";
}
virtual void pushLiveFrame(FrameHessian* image) override
{
// can be used to get the raw image / intensity pyramid.
}
virtual void pushDepthImage(MinimalImageB3* image) override
{
// can be used to get the raw image with depth overlay.
}
virtual bool needPushDepthImage() override
{
return false;
}
virtual void pushDepthImageFloat(MinimalImageF* image, FrameHessian* KF ) override
{
printf("OUT: Predicted depth for KF %d (id %d, time %f, internal frame-ID %d). CameraToWorld:\n",
KF->frameID,
KF->shell->incoming_id,
KF->shell->timestamp,
KF->shell->id);
std::cout << KF->shell->camToWorld.matrix3x4() << "\n";
int maxWrite = 5;
for(int y=0;y<image->h;y++)
{
for(int x=0;x<image->w;x++)
{
if(image->at(x,y) <= 0) continue;
printf("OUT: Example Idepth at pixel (%d,%d): %f.\n", x,y,image->at(x,y));
maxWrite--;
if(maxWrite==0) break;
}
if(maxWrite==0) break;
}
}
std::ofstream pclFile;
};
}
}