From 4eda8efd42a097925ebc2c43bd42bcd719ce1e6c Mon Sep 17 00:00:00 2001 From: Vadim Pisarevsky Date: Tue, 23 May 2017 18:16:40 +0300 Subject: [PATCH] resolves https://github.com/opencv/opencv/issues/7792 --- modules/core/src/arithm.cpp | 2 +- modules/core/test/test_arithm.cpp | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/modules/core/src/arithm.cpp b/modules/core/src/arithm.cpp index 9c2c126ffb..0bcf935c77 100644 --- a/modules/core/src/arithm.cpp +++ b/modules/core/src/arithm.cpp @@ -1276,7 +1276,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op) src1 = src1.reshape(1); src2 = src2.reshape(1); Mat dst = _dst.getMat().reshape(1); - size_t esz = src1.elemSize(); + size_t esz = std::max(src1.elemSize(), (size_t)1); size_t blocksize0 = (size_t)(BLOCK_SIZE + esz-1)/esz; BinaryFuncC func = getCmpFunc(depth1); diff --git a/modules/core/test/test_arithm.cpp b/modules/core/test/test_arithm.cpp index a23cee91dd..58bec68f6f 100644 --- a/modules/core/test/test_arithm.cpp +++ b/modules/core/test/test_arithm.cpp @@ -1912,3 +1912,13 @@ TEST(Subtract, scalarc4_matc4) ASSERT_EQ(0, cv::norm(cv::Mat(5, 5, CV_8UC4, cv::Scalar::all(250)), destImage, cv::NORM_INF)); } + +TEST(Compare, empty) +{ + cv::Mat temp, dst1, dst2; + cv::compare(temp, temp, dst1, cv::CMP_EQ); + dst2 = temp > 5; + + EXPECT_TRUE(dst1.empty()); + EXPECT_TRUE(dst2.empty()); +}