EstervQrCode 1.1.1
Library for qr code manipulation
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 
19 
21 
23 
25 
26 CV_WRAP static inline
27 String dumpBool(bool argument)
28 {
29  return (argument) ? String("Bool: True") : String("Bool: False");
30 }
31 
32 CV_WRAP static inline
33 String dumpInt(int argument)
34 {
35  return cv::format("Int: %d", argument);
36 }
37 
38 CV_WRAP static inline
40 {
41  std::ostringstream oss("Int64: ", std::ios::ate);
42  oss << argument;
43  return oss.str();
44 }
45 
46 CV_WRAP static inline
47 String dumpSizeT(size_t argument)
48 {
49  std::ostringstream oss("size_t: ", std::ios::ate);
50  oss << argument;
51  return oss.str();
52 }
53 
54 CV_WRAP static inline
55 String dumpFloat(float argument)
56 {
57  return cv::format("Float: %.2f", argument);
58 }
59 
60 CV_WRAP static inline
61 String dumpDouble(double argument)
62 {
63  return cv::format("Double: %.2f", argument);
64 }
65 
66 CV_WRAP static inline
67 String dumpCString(const char* argument)
68 {
69  return cv::format("String: %s", argument);
70 }
71 
72 CV_WRAP static inline
73 String dumpString(const String& argument)
74 {
75  return cv::format("String: %s", argument.c_str());
76 }
77 
78 CV_WRAP static inline
79 String dumpRect(const Rect& argument)
80 {
81  return format("rect: (x=%d, y=%d, w=%d, h=%d)", argument.x, argument.y,
82  argument.width, argument.height);
83 }
84 
85 CV_WRAP static inline
87 {
88  return format("term_criteria: (type=%d, max_count=%d, epsilon=%lf",
89  argument.type, argument.maxCount, argument.epsilon);
90 }
91 
92 CV_WRAP static inline
94 {
95  return format("rotated_rect: (c_x=%f, c_y=%f, w=%f, h=%f, a=%f)",
96  argument.center.x, argument.center.y, argument.size.width,
97  argument.size.height, argument.angle);
98 }
99 
100 CV_WRAP static inline
101 String dumpRange(const Range& argument)
102 {
103  if (argument == Range::all())
104  {
105  return "range: all";
106  }
107  else
108  {
109  return format("range: (s=%d, e=%d)", argument.start, argument.end);
110  }
111 }
112 
114 
116 
118 
119 
121 
122 CV_WRAP static inline
123 String testOverloadResolution(int value, const Point& point = Point(42, 24))
124 {
125  return format("overload (int=%d, point=(x=%d, y=%d))", value, point.x,
126  point.y);
127 }
128 
129 CV_WRAP static inline
130 String testOverloadResolution(const Rect& rect)
131 {
132  return format("overload (rect=(x=%d, y=%d, w=%d, h=%d))", rect.x, rect.y,
133  rect.width, rect.height);
134 }
135 
136 CV_WRAP static inline
137 RotatedRect testRotatedRect(float x, float y, float w, float h, float angle)
138 {
139  return RotatedRect(Point2f(x, y), Size2f(w, h), angle);
140 }
141 
142 CV_WRAP static inline
143 std::vector<RotatedRect> testRotatedRectVector(float x, float y, float w, float h, float angle)
144 {
146  for (int i = 0; i < 10; i++)
147  result.push_back(RotatedRect(Point2f(x + i, y + 2 * i), Size2f(w, h), angle + 10 * i));
148  return result;
149 }
150 
151 CV_WRAP static inline
152 int testOverwriteNativeMethod(int argument)
153 {
154  return argument;
155 }
156 
157 CV_WRAP static inline
158 String testReservedKeywordConversion(int positional_argument, int lambda = 2, int from = 3)
159 {
160  return format("arg=%d, lambda=%d, from=%d", positional_argument, lambda, from);
161 }
162 
163 CV_WRAP static inline
164 void generateVectorOfRect(size_t len, CV_OUT std::vector<Rect>& vec)
165 {
166  vec.resize(len);
167  if (len > 0)
168  {
169  RNG rng(12345);
170  Mat tmp(static_cast<int>(len), 1, CV_32SC4);
171  rng.fill(tmp, RNG::UNIFORM, 10, 20);
172  tmp.copyTo(vec);
173  }
174 }
175 
176 CV_WRAP static inline
177 void generateVectorOfInt(size_t len, CV_OUT std::vector<int>& vec)
178 {
179  vec.resize(len);
180  if (len > 0)
181  {
182  RNG rng(554433);
183  Mat tmp(static_cast<int>(len), 1, CV_32SC1);
184  rng.fill(tmp, RNG::UNIFORM, -10, 10);
185  tmp.copyTo(vec);
186  }
187 }
188 
189 CV_WRAP static inline
190 void generateVectorOfMat(size_t len, int rows, int cols, int dtype, CV_OUT std::vector<Mat>& vec)
191 {
192  vec.resize(len);
193  if (len > 0)
194  {
195  RNG rng(65431);
196  for (size_t i = 0; i < len; ++i)
197  {
198  vec[i].create(rows, cols, dtype);
199  rng.fill(vec[i], RNG::UNIFORM, 0, 10);
200  }
201  }
202 }
203 
204 CV_WRAP static inline
205 void testRaiseGeneralException()
206 {
207  throw std::runtime_error("exception text");
208 }
209 
210 CV_WRAP static inline
211 AsyncArray testAsyncArray(InputArray argument)
212 {
213  AsyncPromise p;
214  p.setValue(argument);
215  return p.getArrayResult();
216 }
217 
218 CV_WRAP static inline
219 AsyncArray testAsyncException()
220 {
221  AsyncPromise p;
222  try
223  {
224  CV_Error(Error::StsOk, "Test: Generated async error");
225  }
226  catch (const cv::Exception& e)
227  {
228  p.setException(e);
229  }
230  return p.getArrayResult();
231 }
232 
233 CV_WRAP static inline
234 String dumpVec2i(const cv::Vec2i value = cv::Vec2i(42, 24)) {
235  return format("Vec2i(%d, %d)", value[0], value[1]);
236 }
237 
238 struct CV_EXPORTS_W_SIMPLE ClassWithKeywordProperties {
239  CV_PROP_RW int lambda;
240  CV_PROP int except;
241 
242  CV_WRAP explicit ClassWithKeywordProperties(int lambda_arg = 24, int except_arg = 42)
243  {
244  lambda = lambda_arg;
245  except = except_arg;
246  }
247 };
248 
249 struct CV_EXPORTS_W_PARAMS FunctionParams
250 {
251  CV_PROP_RW int lambda = -1;
252  CV_PROP_RW float sigma = 0.0f;
253 
254  FunctionParams& setLambda(int value) CV_NOEXCEPT
255  {
256  lambda = value;
257  return *this;
258  }
259 
260  FunctionParams& setSigma(float value) CV_NOEXCEPT
261  {
262  sigma = value;
263  return *this;
264  }
265 };
266 
267 CV_WRAP static inline String
268 copyMatAndDumpNamedArguments(InputArray src, OutputArray dst,
269  const FunctionParams& params = FunctionParams())
270 {
271  src.copyTo(dst);
272  return format("lambda=%d, sigma=%.1f", params.lambda,
273  params.sigma);
274 }
275 
276 namespace nested {
277 CV_WRAP static inline bool testEchoBooleanFunction(bool flag) {
278  return flag;
279 }
280 
281 class CV_EXPORTS_W CV_WRAP_AS(ExportClassName) OriginalClassName
282 {
283 public:
284  struct CV_EXPORTS_W_SIMPLE Params
285  {
286  CV_PROP_RW int int_value;
287  CV_PROP_RW float float_value;
288 
289  CV_WRAP explicit Params(int int_param = 123, float float_param = 3.5f)
290  {
291  int_value = int_param;
292  float_value = float_param;
293  }
294  };
295 
296  explicit OriginalClassName(const OriginalClassName::Params& params = OriginalClassName::Params())
297  {
298  params_ = params;
299  }
300 
301  CV_WRAP int getIntParam() const
302  {
303  return params_.int_value;
304  }
305 
306  CV_WRAP float getFloatParam() const
307  {
308  return params_.float_value;
309  }
310 
311  CV_WRAP static std::string originalName()
312  {
313  return "OriginalClassName";
314  }
315 
316  CV_WRAP static Ptr<OriginalClassName>
317  create(const OriginalClassName::Params& params = OriginalClassName::Params())
318  {
319  return makePtr<OriginalClassName>(params);
320  }
321 
322 private:
323  OriginalClassName::Params params_;
324 };
325 
326 typedef OriginalClassName::Params OriginalClassName_Params;
327 } // namespace nested
328 
330 
331 namespace fs {
333 } // namespace fs
334 
336 } // namespace cv::utils
337 
339 
340 CV_WRAP static inline
341 int setLogLevel(int level)
342 {
343  // NB: Binding generators doesn't work with enums properly yet, so we define separate overload here
345 }
346 
347 CV_WRAP static inline
348 int getLogLevel()
349 {
351 }
352 
354 
355 } // namespaces cv / utils
356 
357 #endif // OPENCV_CORE_BINDINGS_UTILS_HPP
T c_str(T... args)
Class passed to an error.
Definition: core.hpp:115
Template class for 2D points specified by its coordinates x and y.
Definition: types.hpp:163
_Tp y
y coordinate of the point
Definition: types.hpp:202
_Tp x
x coordinate of the point
Definition: types.hpp:201
@ UNIFORM
Definition: core.hpp:2891
Template class specifying a continuous subsequence (slice) of a sequence.
Definition: types.hpp:623
int end
Definition: types.hpp:631
int start
Definition: types.hpp:631
static Range all()
Template class for 2D rectangles.
Definition: types.hpp:444
_Tp x
x coordinate of the top-left corner
Definition: types.hpp:480
_Tp y
y coordinate of the top-left corner
Definition: types.hpp:481
_Tp width
width of the rectangle
Definition: types.hpp:482
_Tp height
height of the rectangle
Definition: types.hpp:483
The class represents rotated (i.e. not up-right) rectangles on a plane.
Definition: types.hpp:531
CV_PROP_RW float angle
returns the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right...
Definition: types.hpp:567
CV_PROP_RW Size2f size
returns width and height of the rectangle
Definition: types.hpp:565
CV_PROP_RW Point2f center
returns the rectangle mass center
Definition: types.hpp:563
_Tp height
the height
Definition: types.hpp:363
_Tp width
the width
Definition: types.hpp:362
The class defining termination criteria for iterative algorithms.
Definition: types.hpp:886
int type
the type of termination criteria: COUNT, EPS or COUNT + EPS
Definition: types.hpp:914
int maxCount
the maximum number of iterations/elements
Definition: types.hpp:915
double epsilon
the desired accuracy
Definition: types.hpp:916
Template class for short numerical vectors, a partial case of Matx.
Definition: matx.hpp:369
Definition: mat.hpp:387
Point2i Point
Definition: types.hpp:209
std::string String
Definition: cvstd.hpp:151
InputArray InputArrayOfArrays
Definition: mat.hpp:443
Point_< float > Point2f
Definition: types.hpp:207
const _OutputArray & OutputArray
Definition: mat.hpp:444
CV__DEBUG_NS_END typedef const _InputArray & InputArray
Definition: mat.hpp:442
Size_< float > Size2f
Definition: types.hpp:368
const CvArr * angle
Definition: core_c.h:1194
int rows
Definition: core_c.h:257
int CvScalar value
Definition: core_c.h:720
int cols
Definition: core_c.h:221
CvRect rect
Definition: core_c.h:193
CvRNG * rng
Definition: core_c.h:1250
const CvArr CvArr * x
Definition: core_c.h:1195
const CvArr const CvArr CvArr * result
Definition: core_c.h:1423
const CvArr * y
Definition: core_c.h:1187
#define CV_32SC1
Definition: interface.h:112
int64_t int64
Definition: interface.h:61
#define CV_32SC4
Definition: interface.h:115
CV_EXPORTS LogLevel getLogLevel()
CV_EXPORTS LogLevel setLogLevel(LogLevel logLevel)
static CV_WRAP String dumpRange(const Range &argument)
Definition: bindings_utils.hpp:101
static CV_WRAP String dumpSizeT(size_t argument)
Definition: bindings_utils.hpp:47
#define CV_EXPORTS_W_SIMPLE
Definition: cvdef.h:473
CV_EXPORTS_W String dumpInputArray(InputArray argument)
CV_EXPORTS_W String dumpVectorOfDouble(const std::vector< double > &vec)
CV_EXPORTS_W String dumpInputOutputArray(InputOutputArray argument)
#define CV_OUT
Definition: cvdef.h:478
static CV_WRAP String dumpCString(const char *argument)
Definition: bindings_utils.hpp:67
static CV_WRAP String dumpBool(bool argument)
Definition: bindings_utils.hpp:27
#define CV_Error(code, msg)
Call the error handler.
Definition: base.hpp:320
static CV_WRAP String dumpDouble(double argument)
Definition: bindings_utils.hpp:61
#define CV_EXPORTS_W
Definition: cvdef.h:472
#define CV_PROP
Definition: cvdef.h:479
#define CV_NOEXCEPT
Definition: cvdef.h:800
static CV_WRAP String dumpInt64(int64 argument)
Definition: bindings_utils.hpp:39
static CV_WRAP String dumpRect(const Rect &argument)
Definition: bindings_utils.hpp:79
#define CV_PROP_RW
Definition: cvdef.h:480
static CV_WRAP String dumpString(const String &argument)
Definition: bindings_utils.hpp:73
static CV_WRAP String dumpFloat(float argument)
Definition: bindings_utils.hpp:55
static CV_WRAP String dumpTermCriteria(const TermCriteria &argument)
Definition: bindings_utils.hpp:86
CV_EXPORTS_W String dumpVectorOfInt(const std::vector< int > &vec)
static CV_WRAP String dumpInt(int argument)
Definition: bindings_utils.hpp:33
CV_EXPORTS_W String dumpInputArrayOfArrays(InputArrayOfArrays argument)
CV_EXPORTS String format(const char *fmt,...) CV_FORMAT_PRINTF(1
Returns a text string formatted using the printf-like expression.
#define CV_WRAP
Definition: cvdef.h:481
CV_EXPORTS_W String dumpInputOutputArrayOfArrays(InputOutputArrayOfArrays argument)
static CV_WRAP String dumpRotatedRect(const RotatedRect &argument)
Definition: bindings_utils.hpp:93
CV_EXPORTS_W String dumpVectorOfRect(const std::vector< Rect > &vec)
#define CV_EXPORTS_W_PARAMS
Definition: cvdef.h:476
CV_EXPORTS CV_WRAP_AS(goodFeaturesToTrackWithQuality) void goodFeaturesToTrack(InputArray image
Same as above, but returns also quality measure of the detected corners.
OutputArray dst
Definition: imgproc.hpp:3564
@ StsOk
everything is ok
Definition: base.hpp:69
CV_EXPORTS_W cv::String getCacheDirectoryForDownloads()
LogLevel
Supported logging levels and their semantic.
Definition: logger.defines.hpp:25
"black box" representation of the file storage associated with a file on disk.
Definition: calib3d.hpp:441
T str(T... args)
int width
Definition: types_c.h:835
int y
Definition: types_c.h:834
int x
Definition: types_c.h:833
int height
Definition: types_c.h:836