Skip to content

Commit 3e1ebad

Browse files
committed
debugging code for Large Scale Depth Fusion
1 parent b61fe4e commit 3e1ebad

File tree

2 files changed

+81
-1
lines changed

2 files changed

+81
-1
lines changed

modules/rgbd/samples/large_kinfu_LCD_demo.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,15 @@ int main(int argc, char** argv)
173173
// These params can be different for each depth sensor
174174
ds->updateParams(*params);
175175

176+
//DEBUG for copyroom dataset
177+
if (0)
178+
{
179+
params->frameSize = Size(640, 480);
180+
params->intr = Matx33f{ 583, 0, 320, /**/ 0, 583, 240, /**/ 0, 0, 1 };
181+
params->depthFactor = 1000.f;
182+
params->rgb_intr = Matx33f{ 582.871f, 0, 320, /**/ 0, 582.871f, 240, /**/ 0, 0, 1 };
183+
}
184+
176185
cv::setUseOptimized(true);
177186

178187
if (!idle)
@@ -181,7 +190,7 @@ int main(int argc, char** argv)
181190
const auto& volParams = largeKinfu->getParams().volumeParams;
182191

183192
if (!modelBin.empty())
184-
LargeKinfu->setModelForLCD(modelBin, modelTxt, inputSize, backend, target);
193+
largeKinfu->setModelForLCD(modelBin, modelTxt, inputSize, backend, target);
185194

186195
#ifdef HAVE_OPENCV_VIZ
187196
cv::viz::Viz3d window(vizWindowName);

modules/rgbd/src/large_kinfu.cpp

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
#include "precomp.hpp"
99
#include "loop_closure_detection.hpp"
1010

11+
//DEBUG
12+
#include "opencv2/viz.hpp"
13+
1114
namespace cv
1215
{
1316
namespace large_kinfu
@@ -335,8 +338,51 @@ bool LargeKinfuImpl<MatType>::updateT(const MatType& _depth, const Mat& _img)
335338
}
336339
}
337340

341+
//DEBUG
342+
auto drawScene = [&]()
343+
{
344+
viz::Viz3d view("debug");
345+
std::vector<viz::Color> colors = { viz::Color::amethyst(), viz::Color::apricot(), viz::Color::azure(),
346+
viz::Color::bluberry(), viz::Color::blue(), viz::Color::brown(),
347+
viz::Color::celestial_blue(), viz::Color::chartreuse(), viz::Color::cherry() };
348+
for (int i = 0; i < submapMgr->submapList.size(); i++)
349+
{
350+
Ptr<detail::Submap<MatType>> ps = submapMgr->submapList[i];
351+
MatType p;
352+
ps->volume->fetchPointsNormals(p, noArray());
353+
354+
Mat pmat; p.copyTo(pmat);
355+
float step = 0.03f;
356+
typedef std::tuple<int, int, int> int3;
357+
std::set<int3> dset;
358+
for (int j = 0; j < pmat.rows; j++)
359+
{
360+
Vec4f pp = pmat.at<Vec4f>(j);
361+
dset.insert(int3(pp[0] / step, pp[1] / step, pp[2] / step));
362+
}
363+
std::vector<Point3f> downsampled;
364+
for (auto ix : dset)
365+
{
366+
int x, y, z;
367+
std::tie(x, y, z) = ix;
368+
downsampled.push_back(Point3f(x * step, y * step, z * step));
369+
}
370+
Mat pp(downsampled);
371+
viz::WCloud c(pp, colors[i % colors.size()]);
372+
Affine3f pm = ps->pose;
373+
//pm = Affine3f(pm.rotation().t(), pm.translation());
374+
view.showWidget(cv::format("d%d", i), c, pm);
375+
}
376+
view.showWidget("3d", viz::WCoordinateSystem());
377+
view.showWidget("plane", viz::WGrid());
378+
view.spin();
379+
};
380+
338381
if(isMapUpdated)
339382
{
383+
//DEBUG
384+
drawScene();
385+
340386
// TODO: Convert constraints to posegraph
341387
Ptr<detail::PoseGraph> poseGraph = submapMgr->MapToPoseGraph();
342388
CV_LOG_INFO(NULL, "Created posegraph");
@@ -349,6 +395,9 @@ bool LargeKinfuImpl<MatType>::updateT(const MatType& _depth, const Mat& _img)
349395

350396
submapMgr->PoseGraphToMap(poseGraph);
351397

398+
//DEBUG
399+
drawScene();
400+
352401
}
353402
CV_LOG_INFO(NULL, "Number of submaps: " << submapMgr->submapList.size());
354403

@@ -361,12 +410,34 @@ template<typename MatType>
361410
void LargeKinfuImpl<MatType>::render(OutputArray image) const
362411
{
363412
CV_TRACE_FUNCTION();
413+
//DEBUG
414+
/*
364415
auto currSubmap = submapMgr->getCurrentSubmap();
365416
//! TODO: Can render be dependent on current submap
366417
MatType pts, nrm;
367418
currSubmap->frame->getPyramidAt(pts, OdometryFrame::PYR_CLOUD, 0);
368419
currSubmap->frame->getPyramidAt(nrm, OdometryFrame::PYR_NORM, 0);
369420
detail::renderPointsNormals(pts, nrm, image, params.lightPose);
421+
*/
422+
Mat places(Size(1280, 900), CV_8UC4);
423+
size_t sz = submapMgr->submapList.size();
424+
for (int i = 0; i < sz; i++)
425+
{
426+
auto s = submapMgr->submapList[i];
427+
MatType pts, nrm, img;
428+
s->frame->getPyramidAt(pts, OdometryFrame::PYR_CLOUD, 0);
429+
s->frame->getPyramidAt(nrm, OdometryFrame::PYR_NORM, 0);
430+
detail::renderPointsNormals(pts, nrm, img, params.lightPose);
431+
MatType smallImg;
432+
resize(img, smallImg, Size(320, 240));
433+
smallImg.copyTo(
434+
places(
435+
Rect(Point(320*(i%4), 240*(i/4)), Size(320, 240))
436+
)
437+
);
438+
}
439+
image.createSameSize(places, CV_8UC4);
440+
places.copyTo(image);
370441
}
371442

372443

0 commit comments

Comments
 (0)