From d8a89ddca783f1cdf13ca8fa02aedf4127c36230 Mon Sep 17 00:00:00 2001 From: Nicolas Pope <nwpope@utu.fi> Date: Sun, 10 Nov 2019 11:57:06 +0200 Subject: [PATCH] Support channel blending --- applications/gui/src/screen.cpp | 14 ++++++++++---- components/operators/CMakeLists.txt | 7 +++---- .../operators/include/ftl/operators/disparity.hpp | 6 ++++++ .../src/sources/stereovideo/stereovideo.cpp | 3 +++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/applications/gui/src/screen.cpp b/applications/gui/src/screen.cpp index a9f4cc023..3b2aae1aa 100644 --- a/applications/gui/src/screen.cpp +++ b/applications/gui/src/screen.cpp @@ -48,11 +48,13 @@ namespace { constexpr char const *const defaultImageViewFragmentShader = R"(#version 330 - uniform sampler2D image; + uniform sampler2D image1; + uniform sampler2D image2; + uniform float blendAmount; out vec4 color; in vec2 uv; void main() { - color = texture(image, uv); + color = blendAmount * texture(image1, uv) + (1.0 - blendAmount) * texture(image2, uv); })"; } @@ -457,8 +459,12 @@ void ftl::gui::Screen::draw(NVGcontext *ctx) { size().x() * r, size().y() * r);*/ mShader.bind(); glActiveTexture(GL_TEXTURE0); - glBindTexture(GL_TEXTURE_2D, mImageID); - mShader.setUniform("image", 0); + glBindTexture(GL_TEXTURE_2D, leftEye_); + glActiveTexture(GL_TEXTURE1); + glBindTexture(GL_TEXTURE_2D, (camera_->getRight().isValid()) ? rightEye_ : leftEye_); + mShader.setUniform("image1", 0); + mShader.setUniform("image2", 1); + mShader.setUniform("blendAmount", (camera_->getChannel() != ftl::codecs::Channel::Left) ? root_->value("blending", 0.5f) : 1.0f); mShader.setUniform("scaleFactor", scaleFactor); mShader.setUniform("position", imagePosition); mShader.drawIndexed(GL_TRIANGLES, 0, 2); diff --git a/components/operators/CMakeLists.txt b/components/operators/CMakeLists.txt index a0a38590e..76e67de02 100644 --- a/components/operators/CMakeLists.txt +++ b/components/operators/CMakeLists.txt @@ -8,9 +8,6 @@ set(OPERSRC src/normals.cpp src/filling.cpp src/filling.cu - src/nvopticalflow.cpp - src/disparity/optflow_smoothing.cu - src/disparity/optflow_smoothing.cpp src/disparity/disp2depth.cu src/disparity/disparity_to_depth.cpp src/disparity/fixstars_sgm.cpp @@ -20,7 +17,9 @@ set(OPERSRC ) if (HAVE_OPTFLOW) - list(APPEND OPERSRC src/nvopticalflow.cpp) + list(APPEND OPERSRC src/nvopticalflow.cpp + src/disparity/optflow_smoothing.cu + src/disparity/optflow_smoothing.cpp) endif() add_library(ftloperators ${OPERSRC}) diff --git a/components/operators/include/ftl/operators/disparity.hpp b/components/operators/include/ftl/operators/disparity.hpp index 07b620280..fa280871d 100644 --- a/components/operators/include/ftl/operators/disparity.hpp +++ b/components/operators/include/ftl/operators/disparity.hpp @@ -1,7 +1,11 @@ #pragma once +#include <ftl/config.h> #include <ftl/operators/operator.hpp> + +#ifdef HAVE_OPTFLOW #include <opencv2/cudaoptflow.hpp> +#endif #include <libsgm.h> @@ -73,6 +77,7 @@ class DisparityToDepth : public ftl::operators::Operator { /* * Optical flow smoothing for depth */ +#ifdef HAVE_OPTFLOW class OpticalFlowTemporalSmoothing : public ftl::operators::Operator { public: explicit OpticalFlowTemporalSmoothing(ftl::Configurable*); @@ -91,6 +96,7 @@ class OpticalFlowTemporalSmoothing : public ftl::operators::Operator { int n_max_; float threshold_; }; +#endif } } diff --git a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp index 0b0cd15a1..003984d8a 100644 --- a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp @@ -126,7 +126,10 @@ void StereoVideoSource::init(const string &file) { pipeline_depth_ = ftl::config::create<ftl::operators::Graph>(host_, "disparity"); pipeline_depth_->append<ftl::operators::FixstarsSGM>("algorithm"); + + #ifdef HAVE_OPTFLOW pipeline_depth_->append<ftl::operators::OpticalFlowTemporalSmoothing>("optflow_filter"); + #endif pipeline_depth_->append<ftl::operators::DisparityBilateralFilter>("bilateral_filter"); pipeline_depth_->append<ftl::operators::DisparityToDepth>("calculate_depth"); -- GitLab