OpenCV 4.5.3(日本語機械翻訳)
bindings_utils.hpp
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 #ifndef OPENCV_CORE_BINDINGS_UTILS_HPP
6 #define OPENCV_CORE_BINDINGS_UTILS_HPP
7
8 #include <opencv2/core/async.hpp>
9 #include <opencv2/core/detail/async_promise.hpp>
10 #include <opencv2/core/utils/logger.hpp>
11
12 #include <stdexcept>
13
14 namespace cv { namespace utils {
17
18CV_EXPORTS_W String dumpInputArray(InputArray argument);
19
20CV_EXPORTS_W String dumpInputArrayOfArrays(InputArrayOfArrays argument);
21
22CV_EXPORTS_W String dumpInputOutputArray(InputOutputArray argument);
23
24CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argument);
25
26CV_WRAP static inline
27String dumpBool(bool argument)
28{
29 return (argument) ? String("Bool: True") : String("Bool: False");
30}
31
32CV_WRAP static inline
33String dumpInt(int argument)
34{
35 return cv::format("Int: %d", argument);
36}
37
38CV_WRAP static inline
39String dumpSizeT(size_t argument)
40{
41 std::ostringstream oss("size_t: ", std::ios::ate);
42 oss << argument;
43 return oss.str();
44}
45
46CV_WRAP static inline
47String dumpFloat(float argument)
48{
49 return cv::format("Float: %.2f", argument);
50}
51
52CV_WRAP static inline
53String dumpDouble(double argument)
54{
55 return cv::format("Double: %.2f", argument);
56}
57
58CV_WRAP static inline
59String dumpCString(const char* argument)
60{
61 return cv::format("String: %s", argument);
62}
63
64CV_WRAP static inline
65String dumpString(const String& argument)
66{
67 return cv::format("String: %s", argument.c_str());
68}
69
70CV_WRAP static inline
71String testOverloadResolution(int value, const Point& point = Point(42, 24))
72{
73 return format("overload (int=%d, point=(x=%d, y=%d))", value, point.x,
74 point.y);
75}
76
77CV_WRAP static inline
78String testOverloadResolution(const Rect& rect)
79{
80 return format("overload (rect=(x=%d, y=%d, w=%d, h=%d))", rect.x, rect.y,
81 rect.width, rect.height);
82}
83
84CV_WRAP static inline
85String dumpRect(const Rect& argument)
86{
87 return format("rect: (x=%d, y=%d, w=%d, h=%d)", argument.x, argument.y,
88 argument.width, argument.height);
89}
90
91CV_WRAP static inline
92String dumpTermCriteria(const TermCriteria& argument)
93{
94 return format("term_criteria: (type=%d, max_count=%d, epsilon=%lf",
95 argument.type, argument.maxCount, argument.epsilon);
96}
97
98CV_WRAP static inline
99String dumpRotatedRect(const RotatedRect& argument)
100{
101 return format("rotated_rect: (c_x=%f, c_y=%f, w=%f, h=%f, a=%f)",
102 argument.center.x, argument.center.y, argument.size.width,
103 argument.size.height, argument.angle);
104}
105
106CV_WRAP static inline
107String dumpRange(const Range& argument)
108{
109 if (argument == Range::all())
110 {
111 return "range: all";
112 }
113 else
114 {
115 return format("range: (s=%d, e=%d)", argument.start, argument.end);
116 }
117}
118
119CV_WRAP static inline
120 void testRaiseGeneralException()
121{
122 throw std::runtime_error("exception text");
123}
124
125CV_WRAP static inline
126AsyncArray testAsyncArray(InputArray argument)
127{
128 AsyncPromise p;
129 p.setValue(argument);
130 return p.getArrayResult();
131}
132
133CV_WRAP static inline
134AsyncArray testAsyncException()
135{
136 AsyncPromise p;
137 try
138 {
139 CV_Error(Error::StsOk, "Test: Generated async error");
140 }
141 catch (const cv::Exception& e)
142 {
143 p.setException(e);
144 }
145 return p.getArrayResult();
146}
147
148 namespace fs {
149 CV_EXPORTS_W cv::String getCacheDirectoryForDownloads();
150} // namespace fs
151
153} // namespace cv::utils
154
156
157CV_WRAP static inline
158 int setLogLevel(int level)
159{
160 // NB: Binding generators doesn't work with enums properly yet, so we define separate overload here
161 return cv::utils::logging::setLogLevel((cv::utils::logging::LogLevel)level);
162}
163
164CV_WRAP static inline
165 int getLogLevel()
166{
168}
169
171
172} // namespaces cv / utils
173
174 #endif // OPENCV_CORE_BINDINGS_UTILS_HPP
Class passed to an error.
Definition: core.hpp:119
CV_EXPORTS LogLevel getLogLevel()
CV_EXPORTS LogLevel setLogLevel(LogLevel logLevel)
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
cv
"black box" representation of the file storage associated with a file on disk.
Definition: aruco.hpp:75