Skip to content

Commit 7c3577f

Browse files
committed
Merge pull request opencv#8779 from vpisarev:empty_cmp_fix
2 parents 15a2c77 + 4eda8ef commit 7c3577f

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

modules/core/src/arithm.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1276,7 +1276,7 @@ void cv::compare(InputArray _src1, InputArray _src2, OutputArray _dst, int op)
12761276
src1 = src1.reshape(1); src2 = src2.reshape(1);
12771277
Mat dst = _dst.getMat().reshape(1);
12781278

1279-
size_t esz = src1.elemSize();
1279+
size_t esz = std::max(src1.elemSize(), (size_t)1);
12801280
size_t blocksize0 = (size_t)(BLOCK_SIZE + esz-1)/esz;
12811281
BinaryFuncC func = getCmpFunc(depth1);
12821282

modules/core/test/test_arithm.cpp

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1912,3 +1912,13 @@ TEST(Subtract, scalarc4_matc4)
19121912

19131913
ASSERT_EQ(0, cv::norm(cv::Mat(5, 5, CV_8UC4, cv::Scalar::all(250)), destImage, cv::NORM_INF));
19141914
}
1915+
1916+
TEST(Compare, empty)
1917+
{
1918+
cv::Mat temp, dst1, dst2;
1919+
cv::compare(temp, temp, dst1, cv::CMP_EQ);
1920+
dst2 = temp > 5;
1921+
1922+
EXPECT_TRUE(dst1.empty());
1923+
EXPECT_TRUE(dst2.empty());
1924+
}

0 commit comments

Comments
 (0)