diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 38ff7ed53..3bd9f2c62 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2644,6 +2644,10 @@ void _OutputArray::assign(const UMat& u) const { u.copyTo(*(Mat*)obj); // TODO check u.getMat() } + else if (k == MATX) + { + u.copyTo(getMat()); // TODO check u.getMat() + } else { CV_Error(Error::StsNotImplemented, ""); @@ -2662,6 +2666,10 @@ void _OutputArray::assign(const Mat& m) const { *(Mat*)obj = m; } + else if (k == MATX) + { + m.copyTo(getMat()); + } else { CV_Error(Error::StsNotImplemented, ""); diff --git a/modules/core/test/test_misc.cpp b/modules/core/test/test_misc.cpp index d37f0ee4f..cd4ec7c5a 100644 --- a/modules/core/test/test_misc.cpp +++ b/modules/core/test/test_misc.cpp @@ -26,3 +26,106 @@ TEST(Core_SaturateCast, NegativeNotClipped) ASSERT_EQ(0xffffffff, val); } + +template +static double maxAbsDiff(const T &t, const U &u) +{ + Mat_ d; + absdiff(t, u, d); + double ret; + minMaxLoc(d, NULL, &ret); + return ret; +} + +TEST(Core_OutputArrayAssign, _Matxd_Matd) +{ + Mat expected = (Mat_(2,3) << 1, 2, 3, .1, .2, .3); + Matx23d actualx; + + { + OutputArray oa(actualx); + oa.assign(expected); + } + + Mat actual = (Mat) actualx; + + EXPECT_LE(maxAbsDiff(expected, actual), 0.0); +} + +TEST(Core_OutputArrayAssign, _Matxd_Matf) +{ + Mat expected = (Mat_(2,3) << 1, 2, 3, .1, .2, .3); + Matx23d actualx; + + { + OutputArray oa(actualx); + oa.assign(expected); + } + + Mat actual = (Mat) actualx; + + EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON); +} + +TEST(Core_OutputArrayAssign, _Matxf_Matd) +{ + Mat expected = (Mat_(2,3) << 1, 2, 3, .1, .2, .3); + Matx23f actualx; + + { + OutputArray oa(actualx); + oa.assign(expected); + } + + Mat actual = (Mat) actualx; + + EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON); +} + +TEST(Core_OutputArrayAssign, _Matxd_UMatd) +{ + Mat expected = (Mat_(2,3) << 1, 2, 3, .1, .2, .3); + UMat uexpected = expected.getUMat(ACCESS_READ); + Matx23d actualx; + + { + OutputArray oa(actualx); + oa.assign(uexpected); + } + + Mat actual = (Mat) actualx; + + EXPECT_LE(maxAbsDiff(expected, actual), 0.0); +} + +TEST(Core_OutputArrayAssign, _Matxd_UMatf) +{ + Mat expected = (Mat_(2,3) << 1, 2, 3, .1, .2, .3); + UMat uexpected = expected.getUMat(ACCESS_READ); + Matx23d actualx; + + { + OutputArray oa(actualx); + oa.assign(uexpected); + } + + Mat actual = (Mat) actualx; + + EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON); +} + +TEST(Core_OutputArrayAssign, _Matxf_UMatd) +{ + Mat expected = (Mat_(2,3) << 1, 2, 3, .1, .2, .3); + UMat uexpected = expected.getUMat(ACCESS_READ); + Matx23f actualx; + + { + OutputArray oa(actualx); + oa.assign(uexpected); + } + + Mat actual = (Mat) actualx; + + EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON); +}