From 49fb944a1e97397c6744e94bde8d481741554468 Mon Sep 17 00:00:00 2001
From: Sebastian Hahta <joseha@utu.fi>
Date: Fri, 24 May 2019 17:53:45 +0300
Subject: [PATCH] Disable sub pixel accuracy in libSGM if filter is used
 (accuracy is lost in conversion when disparityBilateralFilter is used)

---
 components/rgbd-sources/src/algorithms/fixstars_sgm.cpp | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp b/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp
index 24d1435cd..012dffa12 100644
--- a/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp
+++ b/components/rgbd-sources/src/algorithms/fixstars_sgm.cpp
@@ -12,7 +12,9 @@ using cv::Mat;
 FixstarsSGM::FixstarsSGM(nlohmann::json &config) : Disparity(config) {
 	ssgm_ = nullptr;
 	use_filter_ = config.value("use_filter", false);
-	filter_ = cv::cuda::createDisparityBilateralFilter(max_disp_, config.value("filter_radius", 25), config.value("filter_iter", 1));
+	// note: (max_disp_ << 4) libsgm subpixel accuracy.
+	//       What is the impact in the filter? (possible artifacts)
+	filter_ = cv::cuda::createDisparityBilateralFilter(max_disp_ << 4, config.value("filter_radius", 25), config.value("filter_iter", 1));
 }
 
 void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) {
@@ -20,7 +22,7 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) {
 	Mat right_disp;
 
 	Mat lbw, rbw;
-	cv::cvtColor(l, lbw,  cv::COLOR_BGR2GRAY);
+	cv::cvtColor(l, lbw, cv::COLOR_BGR2GRAY);
 	cv::cvtColor(r, rbw, cv::COLOR_BGR2GRAY);
 
 	if (!ssgm_) {
@@ -54,4 +56,4 @@ void FixstarsSGM::compute(const cv::Mat &l, const cv::Mat &r, cv::Mat &disp) {
 	}
 	
 	disp.convertTo(disp, CV_32F, 1.0f/16.0f);
-}
\ No newline at end of file
+}
-- 
GitLab