From ccd16f107d1d46e38bcbf9f0bb6f1f1b39c8dd25 Mon Sep 17 00:00:00 2001 From: Vitaly Tuzov Date: Thu, 29 Mar 2018 20:57:02 +0300 Subject: [PATCH] Fixed IPP based implementation of setTo() for infinity value --- modules/core/src/copy.cpp | 5 ++++ modules/core/test/test_arithm.cpp | 45 +++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) diff --git a/modules/core/src/copy.cpp b/modules/core/src/copy.cpp index 554256ddea..9531270903 100644 --- a/modules/core/src/copy.cpp +++ b/modules/core/src/copy.cpp @@ -478,6 +478,11 @@ static bool ipp_Mat_setTo_Mat(Mat &dst, Mat &_val, Mat &mask) if(dst.channels() > 4) return false; + if (dst.depth() == CV_32F) + for (int i = 0; i < (int)(_val.total()); i++) + if (_val.at(i) < iwTypeGetMin(ipp32f) || _val.at(i) > iwTypeGetMax(ipp32f)) + return false; + if(dst.dims <= 2) { IppiSize size = ippiSize(dst.size()); diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index 72d8964cf6..5e80a55c65 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -2039,4 +2039,49 @@ TEST(Core_minMaxIdx, regression_9207_2) EXPECT_EQ(14, maxIdx[1]); } +TEST(Core_Set, regression_11044) +{ + Mat testFloat(Size(3, 3), CV_32FC1); + Mat testDouble(Size(3, 3), CV_64FC1); + + testFloat.setTo(1); + EXPECT_EQ(1, testFloat.at(0,0)); + testFloat.setTo(std::numeric_limits::infinity()); + EXPECT_EQ(std::numeric_limits::infinity(), testFloat.at(0, 0)); + testFloat.setTo(1); + EXPECT_EQ(1, testFloat.at(0, 0)); + testFloat.setTo(std::numeric_limits::infinity()); + EXPECT_EQ(std::numeric_limits::infinity(), testFloat.at(0, 0)); + + testDouble.setTo(1); + EXPECT_EQ(1, testDouble.at(0, 0)); + testDouble.setTo(std::numeric_limits::infinity()); + EXPECT_EQ(std::numeric_limits::infinity(), testDouble.at(0, 0)); + testDouble.setTo(1); + EXPECT_EQ(1, testDouble.at(0, 0)); + testDouble.setTo(std::numeric_limits::infinity()); + EXPECT_EQ(std::numeric_limits::infinity(), testDouble.at(0, 0)); + + Mat testMask(Size(3, 3), CV_8UC1, Scalar(1)); + + testFloat.setTo(1); + EXPECT_EQ(1, testFloat.at(0, 0)); + testFloat.setTo(std::numeric_limits::infinity(), testMask); + EXPECT_EQ(std::numeric_limits::infinity(), testFloat.at(0, 0)); + testFloat.setTo(1); + EXPECT_EQ(1, testFloat.at(0, 0)); + testFloat.setTo(std::numeric_limits::infinity(), testMask); + EXPECT_EQ(std::numeric_limits::infinity(), testFloat.at(0, 0)); + + + testDouble.setTo(1); + EXPECT_EQ(1, testDouble.at(0, 0)); + testDouble.setTo(std::numeric_limits::infinity(), testMask); + EXPECT_EQ(std::numeric_limits::infinity(), testDouble.at(0, 0)); + testDouble.setTo(1); + EXPECT_EQ(1, testDouble.at(0, 0)); + testDouble.setTo(std::numeric_limits::infinity(), testMask); + EXPECT_EQ(std::numeric_limits::infinity(), testDouble.at(0, 0)); +} + }} // namespace