From: Danny <33044223+danielenricocahall@users.noreply.github.com> Date: Sun, 30 May 2021 20:29:39 +0000 (-0400) Subject: Merge pull request #20054 from danielenricocahall:fix-robertson-calibration-bug X-Git-Tag: submit/tizen/20220120.021815~1^2~62 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=eb9b5fa9a5227ba978f3f36e4fc3f3e0c68e90a6;p=platform%2Fupstream%2Fopencv.git Merge pull request #20054 from danielenricocahall:fix-robertson-calibration-bug Fix Robertson Calibration NaN Bug * add epsilon value for numerical stability in robertson merge * update test to use range based for loop * add comment to test * move the epsilon * address test comments fix windows build warnings fix vector type for tests update tests make threshold float address test comments fix tests and move epsilon again * use scalar::all, move epsilon, and remove print --- diff --git a/modules/photo/src/merge.cpp b/modules/photo/src/merge.cpp index fbeb4639b4..e6a00fedb8 100644 --- a/modules/photo/src/merge.cpp +++ b/modules/photo/src/merge.cpp @@ -344,7 +344,7 @@ public: result += times.at((int)i) * w.mul(im); wsum += times.at((int)i) * times.at((int)i) * w; } - result = result.mul(1 / wsum); + result = result.mul(1 / (wsum + Scalar::all(DBL_EPSILON))); } void process(InputArrayOfArrays src, OutputArray dst, InputArray times) CV_OVERRIDE diff --git a/modules/photo/test/test_hdr.cpp b/modules/photo/test/test_hdr.cpp index 198b83470c..10050abbcb 100644 --- a/modules/photo/test/test_hdr.cpp +++ b/modules/photo/test/test_hdr.cpp @@ -249,4 +249,21 @@ TEST(Photo_CalibrateRobertson, regression) checkEqual(expected, response, 1e-1f, "CalibrateRobertson"); } +TEST(Photo_CalibrateRobertson, bug_18180) +{ + vector images; + vector fn; + string test_path = cvtest::TS::ptr()->get_data_path() + "hdr/exposures/bug_18180/"; + for(int i = 1; i <= 4; ++i) + images.push_back(imread(test_path + std::to_string(i) + ".jpg")); + vector times {15.0f, 2.5f, 0.25f, 0.33f}; + Mat response, expected; + Ptr calibrate = createCalibrateRobertson(2, 0.01f); + calibrate->process(images, response, times); + Mat response_no_nans = response.clone(); + patchNaNs(response_no_nans); + // since there should be no NaNs, original response vs. response with NaNs patched should be identical + EXPECT_EQ(0.0, cv::norm(response, response_no_nans, NORM_L2)); +} + }} // namespace