From 59608907b8bd38ef9dc94ed3ea82cea65d844109 Mon Sep 17 00:00:00 2001 From: Maksim Shabunin Date: Tue, 2 Jun 2020 17:53:30 +0300 Subject: [PATCH] Added countNonZero test for big arrays and disable IPP for some cases --- modules/core/src/count_non_zero.dispatch.cpp | 6 ++++++ modules/core/test/test_countnonzero.cpp | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/modules/core/src/count_non_zero.dispatch.cpp b/modules/core/src/count_non_zero.dispatch.cpp index d0ce1ef989..96b80c0d8c 100644 --- a/modules/core/src/count_non_zero.dispatch.cpp +++ b/modules/core/src/count_non_zero.dispatch.cpp @@ -62,6 +62,12 @@ static bool ipp_countNonZero( Mat &src, int &res ) { CV_INSTRUMENT_REGION_IPP(); +#if defined __APPLE__ || (defined _MSC_VER && defined _M_IX86) + // see https://github.com/opencv/opencv/issues/17453 + if (src.dims <= 2 && src.step > 520000) + return false; +#endif + #if IPP_VERSION_X100 < 201801 // Poor performance of SSE42 if(cv::ipp::getIppTopFeatures() == ippCPUID_SSE42) diff --git a/modules/core/test/test_countnonzero.cpp b/modules/core/test/test_countnonzero.cpp index f75deb01db..fe14affb9c 100644 --- a/modules/core/test/test_countnonzero.cpp +++ b/modules/core/test/test_countnonzero.cpp @@ -276,4 +276,23 @@ INSTANTIATE_TEST_CASE_P(Core, CountNonZeroND, ) ); + +typedef testing::TestWithParam > CountNonZeroBig; + +TEST_P(CountNonZeroBig, /**/) +{ + const int type = get<0>(GetParam()); + const Size sz = get<1>(GetParam()); + + EXPECT_EQ(0, cv::countNonZero(cv::Mat::zeros(sz, type))); + EXPECT_EQ(sz.area(), cv::countNonZero(cv::Mat::ones(sz, type))); +} + +INSTANTIATE_TEST_CASE_P(Core, CountNonZeroBig, + testing::Combine( + testing::Values(CV_8UC1, CV_32FC1), + testing::Values(Size(1, 524190), Size(524190, 1), Size(3840, 2160)) + ) +); + }} // namespace