diff --git a/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp b/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp index 9052f3540e55b4d2c48786f6155b05275f388ffd..f96ebcd81ed7336ab34ba0e24322587a63fd6c3b 100644 --- a/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp +++ b/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp @@ -168,20 +168,6 @@ bool FixstarsSGM::updateOFDisparityFilter() { void FixstarsSGM::compute(ftl::rgbd::Frame &frame, cv::cuda::Stream &stream) { - /*if (!frame.hasChannel(ftl::rgbd::kChanLeftGray)) - { - auto &rgb = frame.getChannel<GpuMat>(ftl::rgbd::kChanLeft, stream); - auto &gray = frame.setChannel<GpuMat>(ftl::rgbd::kChanLeftGray); - cv::cuda::cvtColor(rgb, gray, cv::COLOR_BGR2GRAY, 0, stream); - } - - if (!frame.hasChannel(ftl::rgbd::kChanRightGray)) - { - auto &rgb = frame.getChannel<GpuMat>(ftl::rgbd::kChanRight, stream); - auto &gray = frame.setChannel<GpuMat>(ftl::rgbd::kChanRightGray); - cv::cuda::cvtColor(rgb, gray, cv::COLOR_BGR2GRAY, 0, stream); - }*/ - const auto &l = frame.get<GpuMat>(Channel::Left); const auto &r = frame.get<GpuMat>(Channel::Right); auto &disp = frame.create<GpuMat>(Channel::Disparity, Format<float>(l.size())); @@ -202,41 +188,41 @@ void FixstarsSGM::compute(ftl::rgbd::Frame &frame, cv::cuda::Stream &stream) stream.waitForCompletion(); ssgm_->execute(lbw_.data, rbw_.data, dispt_.data); - GpuMat left_pixels(dispt_, cv::Rect(0, 0, max_disp_, dispt_.rows)); - left_pixels.setTo(0); + // GpuMat left_pixels(dispt_, cv::Rect(0, 0, max_disp_, dispt_.rows)); + // left_pixels.setTo(0); cv::cuda::threshold(dispt_, dispt_, 4096.0f, 0.0f, cv::THRESH_TOZERO_INV, stream); - #ifdef HAVE_OPTFLOW - if (use_off_) { - frame.upload(Channel::Flow, stream); - stream.waitForCompletion(); - off_.filter(dispt_, frame.get<GpuMat>(Channel::Flow), stream); + GpuMat dispt_scaled; + if (l.size() != size_) + { + scaleDisparity(l.size(), dispt_, dispt_scaled, stream); + } + else + { + dispt_scaled = dispt_; } - #endif // TODO: filter could be applied after upscaling (to the upscaled disparity image) if (use_filter_) { filter_->apply( dispt_, - (l.size() == size_) ? l : l_scaled, + l, dispt_, stream ); } - - GpuMat dispt_scaled; - if (l.size() != size_) - { - scaleDisparity(l.size(), dispt_, dispt_scaled, stream); - } - else - { - dispt_scaled = dispt_; - } - + dispt_scaled.convertTo(disp, CV_32F, 1.0f / 16.0f, stream); +#ifdef HAVE_OPTFLOW + // TODO: Optical flow filter expects CV_32F + if (use_off_) { + frame.upload(Channel::Flow, stream); + stream.waitForCompletion(); + off_.filter(disp, frame.get<GpuMat>(Channel::Flow), stream); + } +#endif } void FixstarsSGM::setMask(Mat &mask) { diff --git a/components/rgbd-sources/src/offilter.cpp b/components/rgbd-sources/src/offilter.cpp index 832ed467ac84b4526c838fd01bc88a83d841c571..4d0162a5ad1458b71496e08626a57646b15e89d7 100644 --- a/components/rgbd-sources/src/offilter.cpp +++ b/components/rgbd-sources/src/offilter.cpp @@ -41,6 +41,11 @@ void OFDisparityFilter::filter(ftl::rgbd::Frame &frame, cv::cuda::Stream &stream void OFDisparityFilter::filter(cv::cuda::GpuMat &disp, cv::cuda::GpuMat &optflow, cv::cuda::Stream &stream) { + if (disp.type != CV_32FC1) { + LOG(ERROR) << "Optical flow filter expects CV_32FC1 (TODO)"; + return; + } + ftl::cuda::optflow_filter(disp, optflow, disp_old_, n_max_, threshold_, stream); }