core(MatExpr): fix .type() bug

This commit is contained in:
Alexander Alekhin 2020-02-23 17:05:05 +00:00
parent 150c29356a
commit d54d01ca46
3 changed files with 16 additions and 2 deletions

View File

@ -1257,7 +1257,7 @@ int MatExpr::type() const
if( isInitializer(*this) )
return a.type();
if( isCmp(*this) )
return CV_8U;
return CV_MAKETYPE(CV_8U, a.channels());
return op ? op->type(*this) : -1;
}

View File

@ -2017,6 +2017,17 @@ TEST(Core_MatExpr, issue_13926)
EXPECT_GE(1e-6, cvtest::norm(M2*M1, M2*M2, NORM_INF)) << Mat(M2*M1) << std::endl << Mat(M2*M2);
}
TEST(Core_MatExpr, issue_16655)
{
Mat a(Size(5, 5), CV_32FC3, Scalar::all(1));
Mat b(Size(5, 5), CV_32FC3, Scalar::all(2));
MatExpr ab_expr = a != b;
Mat ab_mat = ab_expr;
EXPECT_EQ(CV_8UC3, ab_expr.type())
<< "MatExpr: CV_8UC3 != " << typeToString(ab_expr.type());
EXPECT_EQ(CV_8UC3, ab_mat.type())
<< "Mat: CV_8UC3 != " << typeToString(ab_mat.type());
}
#ifdef HAVE_EIGEN
TEST(Core_Eigen, eigen2cv_check_Mat_type)

View File

@ -56,7 +56,10 @@ TEST(imagesFromBlob, Regression)
for (int i = 0; i < nbOfImages; i++)
{
ASSERT_EQ(cv::countNonZero(inputImgs[i] != outputImgs[i]), 0);
EXPECT_EQ(0, cvtest::norm(inputImgs[i], outputImgs[i], NORM_INF))
<< "i=" << i
<< " inputImgs[i]=" << inputImgs[i].size
<< " outputImgs[i]=" << outputImgs[i].size;
}
}