From 0a32fc3bb36b1a37e6514ba8e5ae2bfa0e79a09a Mon Sep 17 00:00:00 2001 From: Alexander Alekhin Date: Sun, 22 Mar 2020 02:18:37 +0000 Subject: [PATCH] stereo: smallRegionRemoval() is not inplace --- modules/stereo/src/matching.hpp | 13 ++++++++++--- modules/stereo/src/stereo_binary_bm.cpp | 2 +- modules/stereo/src/stereo_binary_sgbm.cpp | 2 +- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/modules/stereo/src/matching.hpp b/modules/stereo/src/matching.hpp index 10d30a636..c57546062 100644 --- a/modules/stereo/src/matching.hpp +++ b/modules/stereo/src/matching.hpp @@ -493,6 +493,7 @@ namespace cv template void smallRegionRemoval(const Mat ¤tMap, int t, Mat &out) { + CV_Assert(currentMap.data != out.data && "inplace is not supported"); CV_Assert(currentMap.cols == out.cols); CV_Assert(currentMap.rows == out.rows); CV_Assert(t >= 0); @@ -511,16 +512,22 @@ namespace cv int speckle_size = 0; st = 0; dr = 0; - for (int i = 1; i < height - 1; i++) + for (int i = 0; i < height; i++) { int iw = i * width; - for (int j = 1; j < width - 1; j++) + for (int j = 0; j < width; j++) { + if (i < 1 || i >= height - 1 || j < 1 || j >= width - 1) + { + outputMap[iw + j] = 0; + continue; + } + if (map[iw + j] != 0) { outputMap[iw + j] = map[iw + j]; } - else if (map[iw + j] == 0) + else // if (map[iw + j] == 0) { T nr = 1; T avg = 0; diff --git a/modules/stereo/src/stereo_binary_bm.cpp b/modules/stereo/src/stereo_binary_bm.cpp index d6e280bdf..ba4cb007e 100644 --- a/modules/stereo/src/stereo_binary_bm.cpp +++ b/modules/stereo/src/stereo_binary_bm.cpp @@ -402,7 +402,7 @@ namespace cv if(params.regionRemoval == CV_SPECKLE_REMOVAL_AVG_ALGORITHM) { - smallRegionRemoval(disp0,params.speckleWindowSize,disp0); + smallRegionRemoval(disp0.clone(),params.speckleWindowSize,disp0); } else if(params.regionRemoval == CV_SPECKLE_REMOVAL_ALGORITHM) { diff --git a/modules/stereo/src/stereo_binary_sgbm.cpp b/modules/stereo/src/stereo_binary_sgbm.cpp index ded25c7c9..2b23cccf3 100644 --- a/modules/stereo/src/stereo_binary_sgbm.cpp +++ b/modules/stereo/src/stereo_binary_sgbm.cpp @@ -697,7 +697,7 @@ namespace cv aux.create(height,width,CV_16S); Median1x9Filter(disp, aux); Median9x1Filter(aux,disp); - smallRegionRemoval(disp, params.speckleWindowSize, disp); + smallRegionRemoval(disp.clone(), params.speckleWindowSize, disp); } else if(params.regionRemoval == CV_SPECKLE_REMOVAL_ALGORITHM) {