Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/perf/perf_mat.cpp
16354 views
1
#include "perf_precomp.hpp"
2
3
namespace opencv_test
4
{
5
using namespace perf;
6
7
PERF_TEST_P(Size_MatType, Mat_Eye,
8
testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
9
testing::Values(TYPICAL_MAT_TYPES))
10
11
)
12
{
13
Size size = get<0>(GetParam());
14
int type = get<1>(GetParam());
15
Mat diagonalMatrix(size.height, size.width, type);
16
17
declare.out(diagonalMatrix);
18
19
int runs = (size.width <= 640) ? 15 : 5;
20
TEST_CYCLE_MULTIRUN(runs)
21
{
22
diagonalMatrix = Mat::eye(size, type);
23
}
24
25
SANITY_CHECK(diagonalMatrix, 1);
26
}
27
28
PERF_TEST_P(Size_MatType, Mat_Zeros,
29
testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
30
testing::Values(TYPICAL_MAT_TYPES, CV_32FC3))
31
32
)
33
{
34
Size size = get<0>(GetParam());
35
int type = get<1>(GetParam());
36
Mat zeroMatrix(size.height, size.width, type);
37
38
declare.out(zeroMatrix);
39
40
int runs = (size.width <= 640) ? 15 : 5;
41
TEST_CYCLE_MULTIRUN(runs)
42
{
43
zeroMatrix = Mat::zeros(size, type);
44
}
45
46
SANITY_CHECK(zeroMatrix, 1);
47
}
48
49
PERF_TEST_P(Size_MatType, Mat_Clone,
50
testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
51
testing::Values(TYPICAL_MAT_TYPES))
52
53
)
54
{
55
Size size = get<0>(GetParam());
56
int type = get<1>(GetParam());
57
Mat source(size.height, size.width, type);
58
Mat destination(size.height, size.width, type);
59
60
declare.in(source, WARMUP_RNG).out(destination);
61
62
TEST_CYCLE()
63
{
64
Mat tmp = source.clone();
65
CV_UNUSED(tmp);
66
}
67
destination = source.clone();
68
69
SANITY_CHECK(destination, 1);
70
}
71
72
PERF_TEST_P(Size_MatType, Mat_Clone_Roi,
73
testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
74
testing::Values(TYPICAL_MAT_TYPES))
75
76
)
77
{
78
Size size = get<0>(GetParam());
79
int type = get<1>(GetParam());
80
81
unsigned int width = size.width;
82
unsigned int height = size.height;
83
Mat source(height, width, type);
84
Mat destination(size.height/2, size.width/2, type);
85
86
declare.in(source, WARMUP_RNG).out(destination);
87
88
Mat roi(source, Rect(width/4, height/4, 3*width/4, 3*height/4));
89
90
TEST_CYCLE()
91
{
92
Mat tmp = roi.clone();
93
CV_UNUSED(tmp);
94
}
95
destination = roi.clone();
96
97
SANITY_CHECK(destination, 1);
98
}
99
100
PERF_TEST_P(Size_MatType, Mat_CopyToWithMask,
101
testing::Combine(testing::Values(::perf::sz1080p, ::perf::szODD),
102
testing::Values(CV_8UC1, CV_8UC2, CV_8UC3, CV_16UC1, CV_32SC1, CV_32FC4))
103
)
104
{
105
const Size_MatType_t params = GetParam();
106
const Size size = get<0>(params);
107
const int type = get<1>(params);
108
109
Mat src(size, type), dst(size, type), mask(size, CV_8UC1);
110
declare.in(src, mask, WARMUP_RNG).out(dst);
111
112
TEST_CYCLE()
113
{
114
src.copyTo(dst, mask);
115
}
116
117
SANITY_CHECK(dst);
118
}
119
120
PERF_TEST_P(Size_MatType, Mat_SetToWithMask,
121
testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
122
testing::Values(CV_8UC1, CV_8UC2))
123
)
124
{
125
const Size_MatType_t params = GetParam();
126
const Size size = get<0>(params);
127
const int type = get<1>(params);
128
const Scalar sc = Scalar::all(27);
129
130
Mat src(size, type), mask(size, CV_8UC1);
131
declare.in(src, mask, WARMUP_RNG).out(src);
132
133
TEST_CYCLE()
134
{
135
src.setTo(sc, mask);
136
}
137
138
SANITY_CHECK(src);
139
}
140
141
///////////// Transform ////////////////////////
142
143
PERF_TEST_P(Size_MatType, Mat_Transform,
144
testing::Combine(testing::Values(TYPICAL_MAT_SIZES),
145
testing::Values(CV_8UC3, CV_8SC3, CV_16UC3, CV_16SC3, CV_32SC3, CV_32FC3, CV_64FC3))
146
)
147
{
148
const Size_MatType_t params = GetParam();
149
const Size srcSize0 = get<0>(params);
150
const Size srcSize = Size(1, srcSize0.width*srcSize0.height);
151
const int type = get<1>(params);
152
const float transform[] = { 0.5f, 0.f, 0.86602540378f, 128,
153
0.f, 1.f, 0.f, -64,
154
0.86602540378f, 0.f, 0.5f, 32,};
155
Mat mtx(Size(4, 3), CV_32FC1, (void*)transform);
156
157
Mat src(srcSize, type), dst(srcSize, type);
158
randu(src, 0, 30);
159
declare.in(src).out(dst);
160
161
TEST_CYCLE()
162
{
163
cv::transform(src, dst, mtx);
164
}
165
166
SANITY_CHECK(dst, 1e-6, ERROR_RELATIVE);
167
}
168
169
} // namespace
170
171