mirror of
https://github.com/opencv/opencv.git
synced 2026-11-09 18:04:29 -06:00
Merge pull request #30245 from vrabaud:empty_mat
allow empty array with scalar operand in arithm_op
This commit is contained in:
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user