fix _OutputArray::assign() for _OutputArrays of type MATX when data types differ
authorNicu Știurcă <nstiurca@seas.upenn.edu>
Wed, 21 Jan 2015 04:44:03 +0000 (23:44 -0500)
committerNicu Știurcă <nstiurca@seas.upenn.edu>
Wed, 21 Jan 2015 04:49:04 +0000 (23:49 -0500)
modules/core/src/matrix.cpp
modules/core/test/test_misc.cpp

index 04d6fb4..3bd9f2c 100644 (file)
@@ -2668,7 +2668,7 @@ void _OutputArray::assign(const Mat& m) const
     }
     else if (k == MATX)
     {
-        getMat() = m;
+        m.copyTo(getMat());
     }
     else
     {
index d37f0ee..0438065 100644 (file)
@@ -26,3 +26,107 @@ TEST(Core_SaturateCast, NegativeNotClipped)
 
     ASSERT_EQ(0xffffffff, val);
 }
+
+template<typename T, typename U>
+static double maxAbsDiff(const T &t, const U &u)
+{
+  Mat_<double> d;
+  absdiff(t, u, d);
+  double ret;
+  minMaxLoc(d, NULL, &ret);
+  return ret;
+}
+
+TEST(Core_OutputArrayAssign, _Matxd_Matd)
+{
+    Mat expected = (Mat_<double>(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_<float>(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_<double>(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_<double>(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_<float>(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_<double>(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);
+}
+