From 1890157faa99b247cb0ba096c85beed44788e8ba Mon Sep 17 00:00:00 2001 From: Artem Saratovtsev <46279571+DumDereDum@users.noreply.github.com> Date: Fri, 18 Feb 2022 17:58:58 +0300 Subject: [PATCH] Merge pull request #21635 from DumDereDum:issue_21595_3.4 Issue 21595 fix 3.4 branch * bug fix; add test * rewrite tests avoiding vector in tests --- modules/imgproc/src/histogram.cpp | 3 ++- modules/imgproc/test/test_histograms.cpp | 32 ++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/modules/imgproc/src/histogram.cpp b/modules/imgproc/src/histogram.cpp index e66e2e2d23..404bd43188 100644 --- a/modules/imgproc/src/histogram.cpp +++ b/modules/imgproc/src/histogram.cpp @@ -909,7 +909,8 @@ static bool ipp_calchist(const Mat &image, Mat &hist, int histSize, const float* #endif // IPP_DISABLE_HISTOGRAM - https://github.com/opencv/opencv/issues/11544 - if (uniform && (ranges[0][1] - ranges[0][0]) != histSize) + // and https://github.com/opencv/opencv/issues/21595 + if ((uniform && (ranges[0][1] - ranges[0][0]) != histSize) || abs(ranges[0][0]) != cvFloor(ranges[0][0])) return false; Mat ihist = hist; diff --git a/modules/imgproc/test/test_histograms.cpp b/modules/imgproc/test/test_histograms.cpp index afe6e53603..e3316df026 100644 --- a/modules/imgproc/test/test_histograms.cpp +++ b/modules/imgproc/test/test_histograms.cpp @@ -1993,6 +1993,38 @@ TEST(Imgproc_Hist_Calc, badarg) EXPECT_NO_THROW(cv::calcBackProject(&img, 1, channels, hist, backProj, NULL, 1, true)); } +TEST(Imgproc_Hist_Calc, IPP_ranges_with_equal_exponent_21595) +{ + const int channels[] = { 0 }; + float range1[] = { -0.5f, 1.5f }; + const float* ranges[] = { range1 }; + const int hist_size[] = { 2 }; + + uint8_t m[1][6] = { { 0, 1, 0, 1 , 1, 1 } }; + cv::Mat images_u = Mat(1, 6, CV_8UC1, m); + cv::Mat histogram_u; + cv::calcHist(&images_u, 1, channels, noArray(), histogram_u, 1, hist_size, ranges); + + ASSERT_EQ(histogram_u.at(0), 2.f) << "0 not counts correctly, res: " << histogram_u.at(0); + ASSERT_EQ(histogram_u.at(1), 4.f) << "1 not counts correctly, res: " << histogram_u.at(0); +} + +TEST(Imgproc_Hist_Calc, IPP_ranges_with_nonequal_exponent_21595) +{ + const int channels[] = { 0 }; + float range1[] = { -1.3f, 1.5f }; + const float* ranges[] = { range1 }; + const int hist_size[] = { 3 }; + + uint8_t m[1][6] = { { 0, 1, 0, 1 , 1, 1 } }; + cv::Mat images_u = Mat(1, 6, CV_8UC1, m); + cv::Mat histogram_u; + cv::calcHist(&images_u, 1, channels, noArray(), histogram_u, 1, hist_size, ranges); + + ASSERT_EQ(histogram_u.at(0), 0.f) << "not equal to zero, res: " << histogram_u.at(0); + ASSERT_EQ(histogram_u.at(1), 2.f) << "0 not counts correctly, res: " << histogram_u.at(1); + ASSERT_EQ(histogram_u.at(2), 4.f) << "1 not counts correctly, res: " << histogram_u.at(2); +} }} // namespace /* End Of File */