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