Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Tetragramm
GitHub Repository: Tetragramm/opencv
Path: blob/master/modules/core/src/check.cpp
16337 views
1
// This file is part of OpenCV project.
2
// It is subject to the license terms in the LICENSE file found in the top-level directory
3
// of this distribution and at http://opencv.org/license.html.
4
5
#include "precomp.hpp"
6
7
#include "opencv2/core/check.hpp"
8
9
namespace cv {
10
11
const char* depthToString(int depth)
12
{
13
const char* s = detail::depthToString_(depth);
14
return s ? s : "<invalid depth>";
15
}
16
17
const cv::String typeToString(int type)
18
{
19
cv::String s = detail::typeToString_(type);
20
if (s.empty())
21
{
22
static cv::String invalidType("<invalid type>");
23
return invalidType;
24
}
25
return s;
26
}
27
28
29
namespace detail {
30
31
static const char* getTestOpPhraseStr(unsigned testOp)
32
{
33
static const char* _names[] = { "{custom check}", "equal to", "not equal to", "less than or equal to", "less than", "greater than or equal to", "greater than" };
34
CV_DbgAssert(testOp < CV__LAST_TEST_OP);
35
return testOp < CV__LAST_TEST_OP ? _names[testOp] : "???";
36
}
37
static const char* getTestOpMath(unsigned testOp)
38
{
39
static const char* _names[] = { "???", "==", "!=", "<=", "<", ">=", ">" };
40
CV_DbgAssert(testOp < CV__LAST_TEST_OP);
41
return testOp < CV__LAST_TEST_OP ? _names[testOp] : "???";
42
}
43
44
const char* depthToString_(int depth)
45
{
46
static const char* depthNames[] = { "CV_8U", "CV_8S", "CV_16U", "CV_16S", "CV_32S", "CV_32F", "CV_64F", "CV_16F" };
47
return (depth <= CV_16F && depth >= 0) ? depthNames[depth] : NULL;
48
}
49
50
const cv::String typeToString_(int type)
51
{
52
int depth = CV_MAT_DEPTH(type);
53
int cn = CV_MAT_CN(type);
54
if (depth >= 0 && depth <= CV_16F)
55
return cv::format("%sC%d", depthToString_(depth), cn);
56
return cv::String();
57
}
58
59
template<typename T> static CV_NORETURN
60
void check_failed_auto_(const T& v1, const T& v2, const CheckContext& ctx)
61
{
62
std::stringstream ss;
63
ss << ctx.message << " (expected: '" << ctx.p1_str << " " << getTestOpMath(ctx.testOp) << " " << ctx.p2_str << "'), where" << std::endl
64
<< " '" << ctx.p1_str << "' is " << v1 << std::endl;
65
if (ctx.testOp != TEST_CUSTOM && ctx.testOp < CV__LAST_TEST_OP)
66
{
67
ss << "must be " << getTestOpPhraseStr(ctx.testOp) << std::endl;
68
}
69
ss << " '" << ctx.p2_str << "' is " << v2;
70
cv::error(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
71
}
72
void check_failed_MatDepth(const int v1, const int v2, const CheckContext& ctx)
73
{
74
std::stringstream ss;
75
ss << ctx.message << " (expected: '" << ctx.p1_str << " " << getTestOpMath(ctx.testOp) << " " << ctx.p2_str << "'), where" << std::endl
76
<< " '" << ctx.p1_str << "' is " << v1 << " (" << depthToString(v1) << ")" << std::endl;
77
if (ctx.testOp != TEST_CUSTOM && ctx.testOp < CV__LAST_TEST_OP)
78
{
79
ss << "must be " << getTestOpPhraseStr(ctx.testOp) << std::endl;
80
}
81
ss << " '" << ctx.p2_str << "' is " << v2 << " (" << depthToString(v2) << ")";
82
cv::error(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
83
}
84
void check_failed_MatType(const int v1, const int v2, const CheckContext& ctx)
85
{
86
std::stringstream ss;
87
ss << ctx.message << " (expected: '" << ctx.p1_str << " " << getTestOpMath(ctx.testOp) << " " << ctx.p2_str << "'), where" << std::endl
88
<< " '" << ctx.p1_str << "' is " << v1 << " (" << typeToString(v1) << ")" << std::endl;
89
if (ctx.testOp != TEST_CUSTOM && ctx.testOp < CV__LAST_TEST_OP)
90
{
91
ss << "must be " << getTestOpPhraseStr(ctx.testOp) << std::endl;
92
}
93
ss << " '" << ctx.p2_str << "' is " << v2 << " (" << typeToString(v2) << ")";
94
cv::error(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
95
}
96
void check_failed_MatChannels(const int v1, const int v2, const CheckContext& ctx)
97
{
98
check_failed_auto_<int>(v1, v2, ctx);
99
}
100
void check_failed_auto(const int v1, const int v2, const CheckContext& ctx)
101
{
102
check_failed_auto_<int>(v1, v2, ctx);
103
}
104
void check_failed_auto(const size_t v1, const size_t v2, const CheckContext& ctx)
105
{
106
check_failed_auto_<size_t>(v1, v2, ctx);
107
}
108
void check_failed_auto(const float v1, const float v2, const CheckContext& ctx)
109
{
110
check_failed_auto_<float>(v1, v2, ctx);
111
}
112
void check_failed_auto(const double v1, const double v2, const CheckContext& ctx)
113
{
114
check_failed_auto_<double>(v1, v2, ctx);
115
}
116
void check_failed_auto(const Size_<int> v1, const Size_<int> v2, const CheckContext& ctx)
117
{
118
check_failed_auto_< Size_<int> >(v1, v2, ctx);
119
}
120
121
122
template<typename T> static CV_NORETURN
123
void check_failed_auto_(const T& v, const CheckContext& ctx)
124
{
125
std::stringstream ss;
126
ss << ctx.message << ":" << std::endl
127
<< " '" << ctx.p2_str << "'" << std::endl
128
<< "where" << std::endl
129
<< " '" << ctx.p1_str << "' is " << v;
130
cv::error(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
131
}
132
void check_failed_MatDepth(const int v, const CheckContext& ctx)
133
{
134
std::stringstream ss;
135
ss << ctx.message << ":" << std::endl
136
<< " '" << ctx.p2_str << "'" << std::endl
137
<< "where" << std::endl
138
<< " '" << ctx.p1_str << "' is " << v << " (" << depthToString(v) << ")";
139
cv::error(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
140
}
141
void check_failed_MatType(const int v, const CheckContext& ctx)
142
{
143
std::stringstream ss;
144
ss << ctx.message << ":" << std::endl
145
<< " '" << ctx.p2_str << "'" << std::endl
146
<< "where" << std::endl
147
<< " '" << ctx.p1_str << "' is " << v << " (" << typeToString(v) << ")";
148
cv::error(cv::Error::StsError, ss.str(), ctx.func, ctx.file, ctx.line);
149
}
150
void check_failed_MatChannels(const int v, const CheckContext& ctx)
151
{
152
check_failed_auto_<int>(v, ctx);
153
}
154
void check_failed_auto(const int v, const CheckContext& ctx)
155
{
156
check_failed_auto_<int>(v, ctx);
157
}
158
void check_failed_auto(const size_t v, const CheckContext& ctx)
159
{
160
check_failed_auto_<size_t>(v, ctx);
161
}
162
void check_failed_auto(const float v, const CheckContext& ctx)
163
{
164
check_failed_auto_<float>(v, ctx);
165
}
166
void check_failed_auto(const double v, const CheckContext& ctx)
167
{
168
check_failed_auto_<double>(v, ctx);
169
}
170
void check_failed_auto(const Size_<int> v, const CheckContext& ctx)
171
{
172
check_failed_auto_< Size_<int> >(v, ctx);
173
}
174
175
176
}} // namespace
177
178