From cd395d98335c7dd51f8d3b6f38ba64a46e5d2e4b Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Mon, 12 Aug 2019 11:22:57 +0300 Subject: [PATCH] Allow vis of energy channel --- applications/gui/src/camera.cpp | 19 +++++++++++++++++++ applications/gui/src/media_panel.cpp | 9 +++++++++ applications/reconstruct/src/splat_render.cpp | 10 ++++++++++ .../include/ftl/rgbd/detail/source.hpp | 3 ++- components/rgbd-sources/src/streamer.cpp | 2 ++ 5 files changed, 42 insertions(+), 1 deletion(-) diff --git a/applications/gui/src/camera.cpp b/applications/gui/src/camera.cpp index eedf63ffd..f1682a06d 100644 --- a/applications/gui/src/camera.cpp +++ b/applications/gui/src/camera.cpp @@ -222,6 +222,7 @@ void ftl::gui::Camera::showSettings() { void ftl::gui::Camera::setChannel(ftl::rgbd::channel_t c) { channel_ = c; switch (c) { + case ftl::rgbd::kChanEnergy: case ftl::rgbd::kChanFlow: case ftl::rgbd::kChanConfidence: case ftl::rgbd::kChanNormals: @@ -255,6 +256,19 @@ static void visualizeDepthMap( const cv::Mat &depth, cv::Mat &out, out.setTo(cv::Scalar(255, 255, 255), mask); } +static void visualizeEnergy( const cv::Mat &depth, cv::Mat &out, + const float max_depth) +{ + DCHECK(max_depth > 0.0); + + depth.convertTo(out, CV_8U, 255.0f / max_depth); + //out = 255 - out; + cv::Mat mask = (depth >= 39.0f); // TODO (mask for invalid pixels) + + applyColorMap(out, out, cv::COLORMAP_JET); + out.setTo(cv::Scalar(255, 255, 255), mask); +} + static void drawEdges( const cv::Mat &in, cv::Mat &out, const int ksize = 3, double weight = -1.0, const int threshold = 32, const int threshold_type = cv::THRESH_TOZERO) @@ -303,6 +317,11 @@ const GLTexture &ftl::gui::Camera::captureFrame() { cv::Mat tmp; switch(channel_) { + case ftl::rgbd::kChanEnergy: + if (depth.rows == 0) { break; } + visualizeEnergy(depth, tmp, 10.0); + texture_.update(tmp); + break; case ftl::rgbd::kChanDepth: if (depth.rows == 0) { break; } visualizeDepthMap(depth, tmp, 7.0); diff --git a/applications/gui/src/media_panel.cpp b/applications/gui/src/media_panel.cpp index 6fb6d5085..44bb92ec0 100644 --- a/applications/gui/src/media_panel.cpp +++ b/applications/gui/src/media_panel.cpp @@ -184,6 +184,15 @@ MediaPanel::MediaPanel(ftl::gui::Screen *screen) : nanogui::Window(screen, ""), } }); + button = new Button(popup, "Energy"); + button->setFlags(Button::RadioButton); + button->setCallback([this]() { + ftl::gui::Camera *cam = screen_->activeCamera(); + if (cam) { + cam->setChannel(ftl::rgbd::kChanEnergy); + } + }); + } MediaPanel::~MediaPanel() { diff --git a/applications/reconstruct/src/splat_render.cpp b/applications/reconstruct/src/splat_render.cpp index aad8fb818..df9d99a9f 100644 --- a/applications/reconstruct/src/splat_render.cpp +++ b/applications/reconstruct/src/splat_render.cpp @@ -95,6 +95,16 @@ void Splatter::render(ftl::rgbd::Source *src, cudaStream_t stream) { ftl::cuda::int_to_float(depth1_, depth2_, 1.0f / 1000.0f, stream); src->writeFrames(colour1_, depth2_, stream); } + } else if (src->getChannel() == ftl::rgbd::kChanEnergy) { + //ftl::cuda::int_to_float(depth1_, depth2_, 1.0f / 1000.0f, stream); + //if (src->value("splatting", false)) { + //ftl::cuda::splat_points(depth1_, colour1_, normal1_, depth2_, colour2_, params, stream); + //ftl::cuda::int_to_float(depth1_, depth2_, 1.0f / 1000.0f, stream); + src->writeFrames(colour1_, depth2_, stream); + //} else { + //ftl::cuda::int_to_float(depth1_, depth2_, 1.0f / 1000.0f, stream); + // src->writeFrames(colour1_, depth2_, stream); + //} } else if (src->getChannel() == ftl::rgbd::kChanRight) { // Adjust pose to right eye position Eigen::Affine3f transform(Eigen::Translation3f(camera.baseline,0.0f,0.0f)); diff --git a/components/rgbd-sources/include/ftl/rgbd/detail/source.hpp b/components/rgbd-sources/include/ftl/rgbd/detail/source.hpp index b76dd27fa..dcde8047e 100644 --- a/components/rgbd-sources/include/ftl/rgbd/detail/source.hpp +++ b/components/rgbd-sources/include/ftl/rgbd/detail/source.hpp @@ -21,11 +21,12 @@ static const channel_t kChanDeviation = 0x0010; static const channel_t kChanNormals = 0x0020; static const channel_t kChanConfidence = 0x0040; static const channel_t kChanFlow = 0x0080; +static const channel_t kChanEnergy = 0x0100; static const channel_t kChanOverlay1 = 0x1000; inline bool isFloatChannel(ftl::rgbd::channel_t chan) { - return (chan == ftl::rgbd::kChanDepth); + return (chan == ftl::rgbd::kChanDepth || chan == ftl::rgbd::kChanEnergy); } diff --git a/components/rgbd-sources/src/streamer.cpp b/components/rgbd-sources/src/streamer.cpp index 21821c908..e52e20e39 100644 --- a/components/rgbd-sources/src/streamer.cpp +++ b/components/rgbd-sources/src/streamer.cpp @@ -101,6 +101,8 @@ Streamer::Streamer(nlohmann::json &config, Universe *net) net->bind("set_channel", [this](const string &uri, unsigned int chan) { SHARED_LOCK(mutex_,slk); + LOG(INFO) << "SET CHANNEL " << chan; + if (sources_.find(uri) != sources_.end()) { sources_[uri]->src->setChannel((ftl::rgbd::channel_t)chan); } -- GitLab