From e97d18ba812f6f0410850a22eaa04abecf3c9310 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicu=20=C8=98tiurc=C4=83?= Date: Mon, 19 Jan 2015 15:26:51 -0500 Subject: [PATCH 1/3] implement _OutputArray::assign() for _OutputArrays of type MATX --- modules/core/src/matrix.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 38ff7ed53a..04d6fb40f1 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) + { + getMat() = m; + } else { CV_Error(Error::StsNotImplemented, ""); From 7a3ca99894eabd0ea5f6d42797627ad115ee4a3c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicu=20=C8=98tiurc=C4=83?= Date: Tue, 20 Jan 2015 23:44:03 -0500 Subject: [PATCH 2/3] fix _OutputArray::assign() for _OutputArrays of type MATX when data types differ --- modules/core/src/matrix.cpp | 2 +- modules/core/test/test_misc.cpp | 104 ++++++++++++++++++++++++++++++++ 2 files changed, 105 insertions(+), 1 deletion(-) diff --git a/modules/core/src/matrix.cpp b/modules/core/src/matrix.cpp index 04d6fb40f1..3bd9f2c622 100644 --- a/modules/core/src/matrix.cpp +++ b/modules/core/src/matrix.cpp @@ -2668,7 +2668,7 @@ void _OutputArray::assign(const Mat& m) const } else if (k == MATX) { - getMat() = m; + m.copyTo(getMat()); } else { diff --git a/modules/core/test/test_misc.cpp b/modules/core/test/test_misc.cpp index d37f0ee4f6..0438065b88 100644 --- a/modules/core/test/test_misc.cpp +++ b/modules/core/test/test_misc.cpp @@ -26,3 +26,107 @@ 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); +} + From 8722faa1671725144323d7f22b10aabb6cd82f84 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicu=20=C8=98tiurc=C4=83?= Date: Tue, 20 Jan 2015 23:58:05 -0500 Subject: [PATCH 3/3] fix whitespace --- modules/core/test/test_misc.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/modules/core/test/test_misc.cpp b/modules/core/test/test_misc.cpp index 0438065b88..cd4ec7c5a0 100644 --- a/modules/core/test/test_misc.cpp +++ b/modules/core/test/test_misc.cpp @@ -41,7 +41,7 @@ TEST(Core_OutputArrayAssign, _Matxd_Matd) { Mat expected = (Mat_(2,3) << 1, 2, 3, .1, .2, .3); Matx23d actualx; - + { OutputArray oa(actualx); oa.assign(expected); @@ -129,4 +129,3 @@ TEST(Core_OutputArrayAssign, _Matxf_UMatd) EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON); } -