diff --git a/components/operators/include/ftl/operators/disparity.hpp b/components/operators/include/ftl/operators/disparity.hpp index b28bafcb2f73803a68f858656db02967ed0a0d88..07b620280ef10b05a544727a1d73d5b311720684 100644 --- a/components/operators/include/ftl/operators/disparity.hpp +++ b/components/operators/include/ftl/operators/disparity.hpp @@ -24,7 +24,8 @@ class FixstarsSGM : public ftl::operators::Operator { private: bool init(); - + bool updateParameters(); + sgm::StereoSGM *ssgm_; cv::Size size_; cv::cuda::GpuMat lbw_; @@ -72,10 +73,10 @@ class DisparityToDepth : public ftl::operators::Operator { /* * Optical flow smoothing for depth */ -class DisparitySmoothingOF : public ftl::operators::Operator { +class OpticalFlowTemporalSmoothing : public ftl::operators::Operator { public: - explicit DisparitySmoothingOF(ftl::Configurable*); - ~DisparitySmoothingOF(); + explicit OpticalFlowTemporalSmoothing(ftl::Configurable*); + ~OpticalFlowTemporalSmoothing(); inline Operator::Type type() const override { return Operator::Type::OneToOne; } @@ -84,7 +85,7 @@ class DisparitySmoothingOF : public ftl::operators::Operator { private: bool init(); - const ftl::codecs::Channel channel_ = ftl::codecs::Channel::Depth; + const ftl::codecs::Channel channel_ = ftl::codecs::Channel::Disparity; cv::cuda::GpuMat history_; cv::Size size_; int n_max_; diff --git a/components/operators/src/disparity/fixstars_sgm.cpp b/components/operators/src/disparity/fixstars_sgm.cpp index 831ee7a21f7eafcc70e7713bb968e1b642d5a5c1..79a18685ee3ac8732f6721358f8f9d7dc5be4da9 100644 --- a/components/operators/src/disparity/fixstars_sgm.cpp +++ b/components/operators/src/disparity/fixstars_sgm.cpp @@ -41,6 +41,39 @@ FixstarsSGM::FixstarsSGM(ftl::Configurable* cfg) : max_disp_ = 256; LOG(WARNING) << "Invalid value for max_disp, using default value (256)"; } + + cfg->on("P1", [this, cfg](const ftl::config::Event&) { + int P1 = cfg->value("P1", 0); + if (P1 <= 0) { + LOG(WARNING) << "Invalid value for P1 (" << P1 << ")"; + } + else { + P1_ = P1; + updateParameters(); + } + }); + + cfg->on("P2", [this, cfg](const ftl::config::Event&) { + int P2 = cfg->value("P2", 0); + if (P2 < P1_) { + LOG(WARNING) << "Invalid value for P2 (" << P2 << ")"; + } + else { + P2_ = P2; + updateParameters(); + } + }); + + cfg->on("uniqueness", [this, cfg](const ftl::config::Event&) { + double uniqueness = cfg->value("uniqueness", 0.0); + if (uniqueness < 0.0 || uniqueness > 1.0) { + LOG(WARNING) << "Invalid value for uniqueness (" << uniqueness << ")"; + } + else { + uniqueness_ = uniqueness; + updateParameters(); + } + }); } FixstarsSGM::~FixstarsSGM() { @@ -65,6 +98,12 @@ bool FixstarsSGM::init() { return true; } +bool FixstarsSGM::updateParameters() { + if (ssgm_ == nullptr) { return false; } + return this->ssgm_->updateParameters( + sgm::StereoSGM::Parameters(P1_, P2_, uniqueness_, true)); +} + bool FixstarsSGM::apply(Frame &in, Frame &out, Source *src, cudaStream_t stream) { if (!in.hasChannel(Channel::Left) || !in.hasChannel(Channel::Right)) { return false; diff --git a/components/operators/src/disparity/optflow_smoothing.cpp b/components/operators/src/disparity/optflow_smoothing.cpp index 6dd9ff11e2ac62c045f731fc43b3d61399bf376d..a3b32bf4890c017df35253da0733406e8d1a7a59 100644 --- a/components/operators/src/disparity/optflow_smoothing.cpp +++ b/components/operators/src/disparity/optflow_smoothing.cpp @@ -6,7 +6,7 @@ #ifdef HAVE_OPTFLOW -using ftl::operators::DisparitySmoothingOF; +using ftl::operators::OpticalFlowTemporalSmoothing; using ftl::codecs::Channel; using ftl::rgbd::Frame; @@ -19,14 +19,14 @@ using std::vector; template<typename T> static bool inline isValidDisparity(T d) { return (0.0 < d) && (d < 256.0); } // TODO -DisparitySmoothingOF::DisparitySmoothingOF(ftl::Configurable* cfg) : +OpticalFlowTemporalSmoothing::OpticalFlowTemporalSmoothing(ftl::Configurable* cfg) : ftl::operators::Operator(cfg) { size_ = Size(0, 0); n_max_ = cfg->value("history_size", 7); if (n_max_ < 1) { - LOG(WARNING) << "History length must be larger than 0"; + LOG(WARNING) << "History length must be larger than 0, using default (0)"; n_max_ = 7; } @@ -66,7 +66,7 @@ DisparitySmoothingOF::DisparitySmoothingOF(ftl::Configurable* cfg) : }); } -DisparitySmoothingOF::~DisparitySmoothingOF() {} +OpticalFlowTemporalSmoothing::~OpticalFlowTemporalSmoothing() {} bool DisparitySmoothingOF::init() { if (size_ == Size(0, 0)) { return false; } diff --git a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp index 830e202537f30770758e304a1267b5471006571f..0b0cd15a1a584e6811b6483fe36de7bde5293ce3 100644 --- a/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp +++ b/components/rgbd-sources/src/sources/stereovideo/stereovideo.cpp @@ -126,8 +126,8 @@ void StereoVideoSource::init(const string &file) { pipeline_depth_ = ftl::config::create<ftl::operators::Graph>(host_, "disparity"); pipeline_depth_->append<ftl::operators::FixstarsSGM>("algorithm"); + pipeline_depth_->append<ftl::operators::OpticalFlowTemporalSmoothing>("optflow_filter"); pipeline_depth_->append<ftl::operators::DisparityBilateralFilter>("bilateral_filter"); - pipeline_depth_->append<ftl::operators::DisparitySmoothingOF>("optflow_filter"); pipeline_depth_->append<ftl::operators::DisparityToDepth>("calculate_depth"); LOG(INFO) << "StereoVideo source ready...";