Skip to content

Commit cddd7f1

Browse files
authored
Merge pull request opencv#17224 from ganesh-k13:bugfix/calib3d/17201
* Fixed indexing in prefilter * Initialised prefilter * Initialised prefilter with value initialisation * Added TC to trigger different Mem Allocs in BufferBM * Optimize cases with only needed conditions
1 parent ea3c230 commit cddd7f1

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

modules/calib3d/src/stereobm.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,8 @@ class BufferBM
347347
htext(nstripes, NULL),
348348
cbuf0(nstripes, NULL),
349349
sad_short(nstripes, NULL),
350-
hsad_short(nstripes, NULL)
350+
hsad_short(nstripes, NULL),
351+
prefilter()
351352
{
352353
const int wsz = params.SADWindowSize;
353354
const int ndisp = params.numDisparities;
@@ -379,7 +380,7 @@ class BufferBM
379380
if (params.useNormPrefilter())
380381
{
381382
for (size_t i = 0; i < 2; ++i)
382-
area.allocate(prefilter[0], width + params.preFilterSize + 2);
383+
area.allocate(prefilter[i], width + params.preFilterSize + 2);
383384
}
384385
area.commit();
385386

modules/calib3d/test/test_stereomatching.cpp

Lines changed: 49 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -809,6 +809,55 @@ class CV_StereoBMTest : public CV_StereoMatchingTest
809809
}
810810
};
811811

812+
TEST(Calib3d_StereoBM, regression) { CV_StereoBMTest test; test.safe_run(); }
813+
814+
/* < preFilter, < preFilterCap, SADWindowSize > >*/
815+
typedef tuple < int, tuple < int, int > > BufferBM_Params_t;
816+
817+
typedef testing::TestWithParam< BufferBM_Params_t > Calib3d_StereoBM_BufferBM;
818+
819+
const int preFilters[] =
820+
{
821+
StereoBM::PREFILTER_NORMALIZED_RESPONSE,
822+
StereoBM::PREFILTER_XSOBEL
823+
};
824+
825+
const tuple < int, int > useShortsConditions[] =
826+
{
827+
make_tuple(30, 19),
828+
make_tuple(32, 23)
829+
};
830+
831+
TEST_P(Calib3d_StereoBM_BufferBM, memAllocsTest)
832+
{
833+
const int preFilter = get<0>(GetParam());
834+
const int preFilterCap = get<0>(get<1>(GetParam()));
835+
const int SADWindowSize = get<1>(get<1>(GetParam()));
836+
837+
String path = cvtest::TS::ptr()->get_data_path() + "cv/stereomatching/datasets/teddy/";
838+
Mat leftImg = imread(path + "im2.png", 0);
839+
ASSERT_FALSE(leftImg.empty());
840+
Mat rightImg = imread(path + "im6.png", 0);
841+
ASSERT_FALSE(rightImg.empty());
842+
Mat leftDisp;
843+
{
844+
Ptr<StereoBM> bm = StereoBM::create(16,9);
845+
bm->setPreFilterType(preFilter);
846+
bm->setPreFilterCap(preFilterCap);
847+
bm->setBlockSize(SADWindowSize);
848+
bm->compute( leftImg, rightImg, leftDisp);
849+
850+
ASSERT_FALSE(leftDisp.empty());
851+
}
852+
}
853+
854+
INSTANTIATE_TEST_CASE_P(/*nothing*/, Calib3d_StereoBM_BufferBM,
855+
testing::Combine(
856+
testing::ValuesIn(preFilters),
857+
testing::ValuesIn(useShortsConditions)
858+
)
859+
);
860+
812861
//----------------------------------- StereoSGBM test -----------------------------------------------------
813862

814863
class CV_StereoSGBMTest : public CV_StereoMatchingTest
@@ -869,8 +918,6 @@ class CV_StereoSGBMTest : public CV_StereoMatchingTest
869918
}
870919
};
871920

872-
873-
TEST(Calib3d_StereoBM, regression) { CV_StereoBMTest test; test.safe_run(); }
874921
TEST(Calib3d_StereoSGBM, regression) { CV_StereoSGBMTest test; test.safe_run(); }
875922

876923
TEST(Calib3d_StereoSGBM_HH4, regression)

0 commit comments

Comments
 (0)