Merge pull request #30245 from vrabaud:empty_mat

allow empty array with scalar operand in arithm_op
This commit is contained in:
Alexander Smorkalov
2026-10-12 09:22:25 +03:00
committed by GitHub
2 changed files with 12 additions and 2 deletions

View File

@@ -623,9 +623,11 @@ enum { ARITHM_SMALL_DIRECT = 100000 };
static void arithm_op(ew::TOp op, InputArray src1, InputArray src2, OutputArray dst,
InputArray mask, int dtype, int oclop, bool muldiv, const Scalar& params)
{
CV_Assert(src1.empty() == src2.empty());
if (src1.empty() && src2.empty()) // empty inputs -> empty result
if (src1.empty() || src2.empty()) // empty inputs -> empty result
{
CV_Assert((src1.empty() && src2.empty()) ||
(src1.empty() && isScalarArg(src2, src1.channels())) ||
(src2.empty() && isScalarArg(src1, src2.channels())));
dst.release();
if (dtype >= 0)
dst.create(0, 0, dtype);

View File

@@ -4559,4 +4559,12 @@ TEST(Core_Arithm, min_empty)
EXPECT_TRUE(C.empty());
}
TEST(Core_Arithm, empty_sum)
{
cv::Mat empty_mat;
cv::add(empty_mat, cv::Scalar(1.0), empty_mat);
ASSERT_TRUE(empty_mat.empty());
ASSERT_THROW(cv::Mat empty_sum = empty_mat + cv::Scalar(1.0), cv::Exception);
}
}} // namespace