From fb466a6a96fc93b8a2c6a78acdfad3facaa479a9 Mon Sep 17 00:00:00 2001 From: matlabbe Date: Sat, 16 Sep 2023 17:43:00 -0700 Subject: [PATCH] StereoBM/StereoSGBM: Thresholding output to zero when minDisparity is used --- corelib/src/stereo/StereoBM.cpp | 8 ++++++++ corelib/src/stereo/StereoSGBM.cpp | 8 ++++++++ 2 files changed, 16 insertions(+) diff --git a/corelib/src/stereo/StereoBM.cpp b/corelib/src/stereo/StereoBM.cpp index 7d47494665..93958293f8 100644 --- a/corelib/src/stereo/StereoBM.cpp +++ b/corelib/src/stereo/StereoBM.cpp @@ -121,6 +121,14 @@ cv::Mat StereoBM::computeDisparity( stereo->setDisp12MaxDiff(disp12MaxDiff_); stereo->compute(leftMono, rightImage, disparity); #endif + + if(minDisparity_>0) + { + cv::Mat dst; + cv::threshold(disparity, dst, minDisparity_*16, 0, cv::THRESH_TOZERO); + disparity = dst; + } + return disparity; } diff --git a/corelib/src/stereo/StereoSGBM.cpp b/corelib/src/stereo/StereoSGBM.cpp index f5388b2cf9..02c2fffe4d 100644 --- a/corelib/src/stereo/StereoSGBM.cpp +++ b/corelib/src/stereo/StereoSGBM.cpp @@ -113,6 +113,14 @@ cv::Mat StereoSGBM::computeDisparity( mode_); stereo->compute(leftMono, rightImage, disparity); #endif + + if(minDisparity_>0) + { + cv::Mat dst; + cv::threshold(disparity, dst, minDisparity_*16, 0, cv::THRESH_TOZERO); + disparity = dst; + } + return disparity; }