1 #include "test_precomp.hpp"
2
3 using namespace cv;
4 using namespace std;
5
TEST(Core_OutputArrayCreate,_1997)6 TEST(Core_OutputArrayCreate, _1997)
7 {
8 struct local {
9 static void create(OutputArray arr, Size submatSize, int type)
10 {
11 int sizes[] = {submatSize.width, submatSize.height};
12 arr.create(sizeof(sizes)/sizeof(sizes[0]), sizes, type);
13 }
14 };
15
16 Mat mat(Size(512, 512), CV_8U);
17 Size submatSize = Size(256, 256);
18
19 ASSERT_NO_THROW(local::create( mat(Rect(Point(), submatSize)), submatSize, mat.type() ));
20 }
21
TEST(Core_SaturateCast,NegativeNotClipped)22 TEST(Core_SaturateCast, NegativeNotClipped)
23 {
24 double d = -1.0;
25 unsigned int val = cv::saturate_cast<unsigned int>(d);
26
27 ASSERT_EQ(0xffffffff, val);
28 }
29
30 template<typename T, typename U>
maxAbsDiff(const T & t,const U & u)31 static double maxAbsDiff(const T &t, const U &u)
32 {
33 Mat_<double> d;
34 absdiff(t, u, d);
35 double ret;
36 minMaxLoc(d, NULL, &ret);
37 return ret;
38 }
39
TEST(Core_OutputArrayAssign,_Matxd_Matd)40 TEST(Core_OutputArrayAssign, _Matxd_Matd)
41 {
42 Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
43 Matx23d actualx;
44
45 {
46 OutputArray oa(actualx);
47 oa.assign(expected);
48 }
49
50 Mat actual = (Mat) actualx;
51
52 EXPECT_LE(maxAbsDiff(expected, actual), 0.0);
53 }
54
TEST(Core_OutputArrayAssign,_Matxd_Matf)55 TEST(Core_OutputArrayAssign, _Matxd_Matf)
56 {
57 Mat expected = (Mat_<float>(2,3) << 1, 2, 3, .1, .2, .3);
58 Matx23d actualx;
59
60 {
61 OutputArray oa(actualx);
62 oa.assign(expected);
63 }
64
65 Mat actual = (Mat) actualx;
66
67 EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON);
68 }
69
TEST(Core_OutputArrayAssign,_Matxf_Matd)70 TEST(Core_OutputArrayAssign, _Matxf_Matd)
71 {
72 Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
73 Matx23f actualx;
74
75 {
76 OutputArray oa(actualx);
77 oa.assign(expected);
78 }
79
80 Mat actual = (Mat) actualx;
81
82 EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON);
83 }
84
TEST(Core_OutputArrayAssign,_Matxd_UMatd)85 TEST(Core_OutputArrayAssign, _Matxd_UMatd)
86 {
87 Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
88 UMat uexpected = expected.getUMat(ACCESS_READ);
89 Matx23d actualx;
90
91 {
92 OutputArray oa(actualx);
93 oa.assign(uexpected);
94 }
95
96 Mat actual = (Mat) actualx;
97
98 EXPECT_LE(maxAbsDiff(expected, actual), 0.0);
99 }
100
TEST(Core_OutputArrayAssign,_Matxd_UMatf)101 TEST(Core_OutputArrayAssign, _Matxd_UMatf)
102 {
103 Mat expected = (Mat_<float>(2,3) << 1, 2, 3, .1, .2, .3);
104 UMat uexpected = expected.getUMat(ACCESS_READ);
105 Matx23d actualx;
106
107 {
108 OutputArray oa(actualx);
109 oa.assign(uexpected);
110 }
111
112 Mat actual = (Mat) actualx;
113
114 EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON);
115 }
116
TEST(Core_OutputArrayAssign,_Matxf_UMatd)117 TEST(Core_OutputArrayAssign, _Matxf_UMatd)
118 {
119 Mat expected = (Mat_<double>(2,3) << 1, 2, 3, .1, .2, .3);
120 UMat uexpected = expected.getUMat(ACCESS_READ);
121 Matx23f actualx;
122
123 {
124 OutputArray oa(actualx);
125 oa.assign(uexpected);
126 }
127
128 Mat actual = (Mat) actualx;
129
130 EXPECT_LE(maxAbsDiff(expected, actual), FLT_EPSILON);
131 }
132