Skip to content

Fixed indexing in prefilter#17224

Merged
alalek merged 5 commits intoopencv:3.4from
ganesh-k13:bugfix/calib3d/17201
May 14, 2020
Merged

Fixed indexing in prefilter#17224
alalek merged 5 commits intoopencv:3.4from
ganesh-k13:bugfix/calib3d/17201

Conversation

@ganesh-k13
Copy link
Copy Markdown
Contributor

@ganesh-k13 ganesh-k13 commented May 6, 2020

Pull Request Changes:

  1. Fixes Possible code error in stereobm.cpp in calib3d module
  2. Added UT for BufferBM usage in StereoBM

resolves #17201

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

@alalek, is a unit test required to catch this?

@asmorkalov
Copy link
Copy Markdown
Contributor

@ganesh-k13 Thanks for the patch! Yes, unit test is very appreciated.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Sure @asmorkalov, I'll add it. I'm new to this, so I'll read a bit before adding.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

ganesh-k13 commented May 8, 2020

Hi @mshabunin / @asmorkalov / @alalek , I have a basic doubt.
I tried the fix in a sample file:

int main() {
     Mat leftImg = imread("im2.png", 0);
     Mat rightImg = imread("im2.png", 0);
     Mat leftDisp;
     Ptr<StereoBM> bm = StereoBM::create(16,9);
     bm->setPreFilterType(StereoBM::PREFILTER_NORMALIZED_RESPONSE);
     bm->compute( leftImg, rightImg, leftDisp);
     return 0;
 }

I see no crash.
But if I do same in a Test(calib3d/test/test_stereomatching.cpp ):

TEST(Calib3d_StereoBM, regression17201)
 {
     String path = cvtest::TS::ptr()->get_data_path() + "cv/stereomatching/datasets/teddy/";
     Mat leftImg = imread(path + "im2.png", 0);
     ASSERT_FALSE(leftImg.empty());
     Mat rightImg = imread(path + "im2.png", 0);
     ASSERT_FALSE(rightImg.empty());
     Mat leftDisp;
     {
         Ptr<StereoBM> bm = StereoBM::create(16, 9);
         bm->setPreFilterType(StereoBM::PREFILTER_NORMALIZED_RESPONSE);
         bm->compute( leftImg, rightImg, leftDisp);
     }
 }

[1] 17033 segmentation fault (core dumped) bin/opencv_test_calib3d --gtest_filter=Calib3d_StereoBM.regression17201 almost as if change is not there.

Is there anything for this difference in behavior between normal code and gtest code?

@asmorkalov
Copy link
Copy Markdown
Contributor

@ganesh-k13 could you put your sample code to OpenCV samples and build OpenCV with -DBUILD_EXAMPLES=ON. All samples are built with the same compiler options and it should help to reproduce the issue.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Thanks @asmorkalov, I'll try that, I think it is some small config mistake from my end. I'll try some more stuff or post in answers.opencv.

@mshabunin
Copy link
Copy Markdown
Contributor

@ganesh-k13 , prefilter pointers must be initialized with 0, add something like

prefilter[0] = 0;
prefilter[1] = 0;

at the beginning of the BufferBM constructor.

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Thanks, @mshabunin, that fixed the issue.
I had a doubt regarding:

Mat_<float> fixedFloatDisp;
bm->compute( leftImg, rightImg, fixedFloatDisp );
EXPECT_LT(cvtest::norm(fixedFloatDisp, leftDisp, cv::NORM_L2 | cv::NORM_RELATIVE),
0.005 + DBL_EPSILON);

How was the value of 0.005+DBL_EPSILON arrived at?

I was planning to add bm->setPreFilterType(StereoBM::PREFILTER_NORMALIZED_RESPONSE); before compute there(or once again after PREFILTER_XSOBEL is used). Is this ok or I'll add a separate test?

@mshabunin
Copy link
Copy Markdown
Contributor

Looks like this tests does not verify the output, it only checks that integer output does not differ from float output and this error margin is an arbitrary value.

Yes, I think you can add another filter to the same test, or you can make parameterized test (TEST_P(...)).

@ganesh-k13
Copy link
Copy Markdown
Contributor Author

Thanks, @mshabunin , I have added cases, the aim of the cases is to trigger different mem allocs in BufferBM. So I added cases with combinations of preFilterCap, SADWindowSize and preFilterType. I also moved Calib3d_StereoBM, regression up because it was under Calib3d_StereoSBM

@ganesh-k13 ganesh-k13 requested a review from mshabunin May 9, 2020 06:53
@ganesh-k13
Copy link
Copy Markdown
Contributor Author

@alalek , @mshabunin , @asmorkalov any update on this?

@alalek alalek merged commit cddd7f1 into opencv:3.4 May 14, 2020
@alalek alalek mentioned this pull request May 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible code error in stereobm.cpp in calib3d module

4 participants