node-native-win-utils 1.4.0 → 2.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (204) hide show
  1. package/README.md +29 -82
  2. package/binding.gyp +2 -0
  3. package/dist/dirnameLocal.cjs +4 -0
  4. package/dist/dirnameLocal.d.cts +1 -0
  5. package/dist/dirnameLocal.d.mts +1 -0
  6. package/dist/dirnameLocal.mjs +2 -0
  7. package/dist/{index.js → index.cjs} +46 -15
  8. package/dist/{index.d.ts → index.d.cts} +24 -12
  9. package/dist/index.d.mts +191 -0
  10. package/dist/index.mjs +177 -0
  11. package/dist/keyCodes.d.mts +101 -0
  12. package/dist/keyCodes.mjs +201 -0
  13. package/node22.json +16 -0
  14. package/package.json +19 -9
  15. package/prebuilds/win32-x64/node-native-win-utils.node +0 -0
  16. package/src/cpp/keyboard.cpp +141 -140
  17. package/src/cpp/main.cpp +9 -3
  18. package/src/cpp/{capturewindow.cpp → screenshot.cpp} +174 -2
  19. package/src/dirnameLocal.mts +3 -0
  20. package/src/index.mts +454 -0
  21. package/src/keyCodes.mts +203 -0
  22. package/dllCopy.js +0 -14
  23. package/include/opencv2/core/affine.hpp +0 -678
  24. package/include/opencv2/core/async.hpp +0 -105
  25. package/include/opencv2/core/base.hpp +0 -664
  26. package/include/opencv2/core/bindings_utils.hpp +0 -325
  27. package/include/opencv2/core/bufferpool.hpp +0 -40
  28. package/include/opencv2/core/check.hpp +0 -170
  29. package/include/opencv2/core/core.hpp +0 -48
  30. package/include/opencv2/core/core_c.h +0 -3128
  31. package/include/opencv2/core/cuda/block.hpp +0 -211
  32. package/include/opencv2/core/cuda/border_interpolate.hpp +0 -722
  33. package/include/opencv2/core/cuda/color.hpp +0 -309
  34. package/include/opencv2/core/cuda/common.hpp +0 -131
  35. package/include/opencv2/core/cuda/datamov_utils.hpp +0 -113
  36. package/include/opencv2/core/cuda/detail/color_detail.hpp +0 -2018
  37. package/include/opencv2/core/cuda/detail/reduce.hpp +0 -365
  38. package/include/opencv2/core/cuda/detail/reduce_key_val.hpp +0 -502
  39. package/include/opencv2/core/cuda/detail/transform_detail.hpp +0 -392
  40. package/include/opencv2/core/cuda/detail/type_traits_detail.hpp +0 -191
  41. package/include/opencv2/core/cuda/detail/vec_distance_detail.hpp +0 -121
  42. package/include/opencv2/core/cuda/dynamic_smem.hpp +0 -88
  43. package/include/opencv2/core/cuda/emulation.hpp +0 -269
  44. package/include/opencv2/core/cuda/filters.hpp +0 -293
  45. package/include/opencv2/core/cuda/funcattrib.hpp +0 -79
  46. package/include/opencv2/core/cuda/functional.hpp +0 -805
  47. package/include/opencv2/core/cuda/limits.hpp +0 -128
  48. package/include/opencv2/core/cuda/reduce.hpp +0 -209
  49. package/include/opencv2/core/cuda/saturate_cast.hpp +0 -292
  50. package/include/opencv2/core/cuda/scan.hpp +0 -258
  51. package/include/opencv2/core/cuda/simd_functions.hpp +0 -869
  52. package/include/opencv2/core/cuda/transform.hpp +0 -75
  53. package/include/opencv2/core/cuda/type_traits.hpp +0 -90
  54. package/include/opencv2/core/cuda/utility.hpp +0 -230
  55. package/include/opencv2/core/cuda/vec_distance.hpp +0 -232
  56. package/include/opencv2/core/cuda/vec_math.hpp +0 -923
  57. package/include/opencv2/core/cuda/vec_traits.hpp +0 -288
  58. package/include/opencv2/core/cuda/warp.hpp +0 -139
  59. package/include/opencv2/core/cuda/warp_reduce.hpp +0 -76
  60. package/include/opencv2/core/cuda/warp_shuffle.hpp +0 -162
  61. package/include/opencv2/core/cuda.hpp +0 -1279
  62. package/include/opencv2/core/cuda.inl.hpp +0 -763
  63. package/include/opencv2/core/cuda_stream_accessor.hpp +0 -86
  64. package/include/opencv2/core/cuda_types.hpp +0 -144
  65. package/include/opencv2/core/cv_cpu_dispatch.h +0 -381
  66. package/include/opencv2/core/cv_cpu_helper.h +0 -550
  67. package/include/opencv2/core/cvdef.h +0 -973
  68. package/include/opencv2/core/cvstd.hpp +0 -190
  69. package/include/opencv2/core/cvstd.inl.hpp +0 -197
  70. package/include/opencv2/core/cvstd_wrapper.hpp +0 -154
  71. package/include/opencv2/core/detail/async_promise.hpp +0 -71
  72. package/include/opencv2/core/detail/dispatch_helper.impl.hpp +0 -49
  73. package/include/opencv2/core/detail/exception_ptr.hpp +0 -27
  74. package/include/opencv2/core/directx.hpp +0 -184
  75. package/include/opencv2/core/dualquaternion.hpp +0 -979
  76. package/include/opencv2/core/dualquaternion.inl.hpp +0 -487
  77. package/include/opencv2/core/eigen.hpp +0 -402
  78. package/include/opencv2/core/fast_math.hpp +0 -433
  79. package/include/opencv2/core/hal/hal.hpp +0 -256
  80. package/include/opencv2/core/hal/interface.h +0 -190
  81. package/include/opencv2/core/hal/intrin.hpp +0 -939
  82. package/include/opencv2/core/hal/intrin_avx.hpp +0 -3177
  83. package/include/opencv2/core/hal/intrin_avx512.hpp +0 -3090
  84. package/include/opencv2/core/hal/intrin_cpp.hpp +0 -3321
  85. package/include/opencv2/core/hal/intrin_forward.hpp +0 -191
  86. package/include/opencv2/core/hal/intrin_lasx.hpp +0 -3236
  87. package/include/opencv2/core/hal/intrin_msa.hpp +0 -1887
  88. package/include/opencv2/core/hal/intrin_neon.hpp +0 -2610
  89. package/include/opencv2/core/hal/intrin_rvv.hpp +0 -3320
  90. package/include/opencv2/core/hal/intrin_rvv071.hpp +0 -2545
  91. package/include/opencv2/core/hal/intrin_rvv_scalable.hpp +0 -2080
  92. package/include/opencv2/core/hal/intrin_sse.hpp +0 -3467
  93. package/include/opencv2/core/hal/intrin_sse_em.hpp +0 -180
  94. package/include/opencv2/core/hal/intrin_vsx.hpp +0 -1608
  95. package/include/opencv2/core/hal/intrin_wasm.hpp +0 -2782
  96. package/include/opencv2/core/hal/msa_macros.h +0 -1558
  97. package/include/opencv2/core/hal/simd_utils.impl.hpp +0 -186
  98. package/include/opencv2/core/llapi/llapi.h +0 -102
  99. package/include/opencv2/core/mat.hpp +0 -3775
  100. package/include/opencv2/core/mat.inl.hpp +0 -3422
  101. package/include/opencv2/core/matx.hpp +0 -1536
  102. package/include/opencv2/core/neon_utils.hpp +0 -128
  103. package/include/opencv2/core/ocl.hpp +0 -917
  104. package/include/opencv2/core/ocl_genbase.hpp +0 -69
  105. package/include/opencv2/core/opencl/ocl_defs.hpp +0 -82
  106. package/include/opencv2/core/opencl/opencl_info.hpp +0 -212
  107. package/include/opencv2/core/opencl/opencl_svm.hpp +0 -81
  108. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp +0 -602
  109. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp +0 -146
  110. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp +0 -371
  111. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp +0 -272
  112. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +0 -62
  113. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +0 -42
  114. package/include/opencv2/core/opencl/runtime/opencl_clblas.hpp +0 -53
  115. package/include/opencv2/core/opencl/runtime/opencl_clfft.hpp +0 -53
  116. package/include/opencv2/core/opencl/runtime/opencl_core.hpp +0 -84
  117. package/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp +0 -47
  118. package/include/opencv2/core/opencl/runtime/opencl_gl.hpp +0 -53
  119. package/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp +0 -47
  120. package/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp +0 -48
  121. package/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp +0 -42
  122. package/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp +0 -166
  123. package/include/opencv2/core/opengl.hpp +0 -733
  124. package/include/opencv2/core/openvx/ovx_defs.hpp +0 -48
  125. package/include/opencv2/core/operations.hpp +0 -610
  126. package/include/opencv2/core/optim.hpp +0 -302
  127. package/include/opencv2/core/ovx.hpp +0 -28
  128. package/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +0 -72
  129. package/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +0 -153
  130. package/include/opencv2/core/parallel/parallel_backend.hpp +0 -90
  131. package/include/opencv2/core/persistence.hpp +0 -1350
  132. package/include/opencv2/core/private/cv_cpu_include_simd_declarations.hpp +0 -30
  133. package/include/opencv2/core/private.cuda.hpp +0 -169
  134. package/include/opencv2/core/private.hpp +0 -896
  135. package/include/opencv2/core/quaternion.hpp +0 -1696
  136. package/include/opencv2/core/quaternion.inl.hpp +0 -1063
  137. package/include/opencv2/core/saturate.hpp +0 -180
  138. package/include/opencv2/core/simd_intrinsics.hpp +0 -87
  139. package/include/opencv2/core/softfloat.hpp +0 -514
  140. package/include/opencv2/core/sse_utils.hpp +0 -652
  141. package/include/opencv2/core/traits.hpp +0 -417
  142. package/include/opencv2/core/types.hpp +0 -2457
  143. package/include/opencv2/core/types_c.h +0 -2126
  144. package/include/opencv2/core/utility.hpp +0 -1229
  145. package/include/opencv2/core/utils/allocator_stats.hpp +0 -29
  146. package/include/opencv2/core/utils/allocator_stats.impl.hpp +0 -158
  147. package/include/opencv2/core/utils/buffer_area.private.hpp +0 -136
  148. package/include/opencv2/core/utils/configuration.private.hpp +0 -22
  149. package/include/opencv2/core/utils/filesystem.hpp +0 -82
  150. package/include/opencv2/core/utils/filesystem.private.hpp +0 -66
  151. package/include/opencv2/core/utils/fp_control.private.hpp +0 -29
  152. package/include/opencv2/core/utils/fp_control_utils.hpp +0 -69
  153. package/include/opencv2/core/utils/instrumentation.hpp +0 -125
  154. package/include/opencv2/core/utils/lock.private.hpp +0 -119
  155. package/include/opencv2/core/utils/logger.defines.hpp +0 -42
  156. package/include/opencv2/core/utils/logger.hpp +0 -218
  157. package/include/opencv2/core/utils/logtag.hpp +0 -28
  158. package/include/opencv2/core/utils/plugin_loader.private.hpp +0 -165
  159. package/include/opencv2/core/utils/tls.hpp +0 -235
  160. package/include/opencv2/core/utils/trace.hpp +0 -252
  161. package/include/opencv2/core/utils/trace.private.hpp +0 -421
  162. package/include/opencv2/core/va_intel.hpp +0 -75
  163. package/include/opencv2/core/version.hpp +0 -26
  164. package/include/opencv2/core/vsx_utils.hpp +0 -1047
  165. package/include/opencv2/core.hpp +0 -3365
  166. package/include/opencv2/imgcodecs/imgcodecs.hpp +0 -48
  167. package/include/opencv2/imgcodecs/imgcodecs_c.h +0 -1
  168. package/include/opencv2/imgcodecs/ios.h +0 -59
  169. package/include/opencv2/imgcodecs/legacy/constants_c.h +0 -54
  170. package/include/opencv2/imgcodecs/macosx.h +0 -20
  171. package/include/opencv2/imgcodecs.hpp +0 -407
  172. package/include/opencv2/imgproc/bindings.hpp +0 -34
  173. package/include/opencv2/imgproc/detail/gcgraph.hpp +0 -395
  174. package/include/opencv2/imgproc/hal/hal.hpp +0 -246
  175. package/include/opencv2/imgproc/hal/interface.h +0 -46
  176. package/include/opencv2/imgproc/imgproc.hpp +0 -48
  177. package/include/opencv2/imgproc/imgproc_c.h +0 -1177
  178. package/include/opencv2/imgproc/segmentation.hpp +0 -141
  179. package/include/opencv2/imgproc/types_c.h +0 -659
  180. package/include/opencv2/imgproc.hpp +0 -5035
  181. package/include/opencv2/opencv_modules.hpp +0 -17
  182. package/include/tesseract/baseapi.h +0 -820
  183. package/include/tesseract/capi.h +0 -485
  184. package/include/tesseract/export.h +0 -37
  185. package/include/tesseract/ltrresultiterator.h +0 -235
  186. package/include/tesseract/ocrclass.h +0 -158
  187. package/include/tesseract/osdetect.h +0 -139
  188. package/include/tesseract/pageiterator.h +0 -364
  189. package/include/tesseract/publictypes.h +0 -281
  190. package/include/tesseract/renderer.h +0 -334
  191. package/include/tesseract/resultiterator.h +0 -250
  192. package/include/tesseract/tesseract.h +0 -40
  193. package/include/tesseract/unichar.h +0 -174
  194. package/include/tesseract/version.h +0 -34
  195. package/include/tesseract/version.h.in +0 -34
  196. package/libs/libjpeg-turbo.lib +0 -0
  197. package/libs/libpng.lib +0 -0
  198. package/libs/opencv_core470.lib +0 -0
  199. package/libs/opencv_imgcodecs470.lib +0 -0
  200. package/libs/opencv_imgproc470.lib +0 -0
  201. package/libs/tesseract.lib +0 -0
  202. package/libs/zlib.lib +0 -0
  203. /package/dist/{keyCodes.js → keyCodes.cjs} +0 -0
  204. /package/dist/{keyCodes.d.ts → keyCodes.d.cts} +0 -0
@@ -1,1229 +0,0 @@
1
- /*M///////////////////////////////////////////////////////////////////////////////////////
2
- //
3
- // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
4
- //
5
- // By downloading, copying, installing or using the software you agree to this license.
6
- // If you do not agree to this license, do not download, install,
7
- // copy or use the software.
8
- //
9
- //
10
- // License Agreement
11
- // For Open Source Computer Vision Library
12
- //
13
- // Copyright (C) 2000-2008, Intel Corporation, all rights reserved.
14
- // Copyright (C) 2009, Willow Garage Inc., all rights reserved.
15
- // Copyright (C) 2013, OpenCV Foundation, all rights reserved.
16
- // Copyright (C) 2015, Itseez Inc., all rights reserved.
17
- // Third party copyrights are property of their respective owners.
18
- //
19
- // Redistribution and use in source and binary forms, with or without modification,
20
- // are permitted provided that the following conditions are met:
21
- //
22
- // * Redistribution's of source code must retain the above copyright notice,
23
- // this list of conditions and the following disclaimer.
24
- //
25
- // * Redistribution's in binary form must reproduce the above copyright notice,
26
- // this list of conditions and the following disclaimer in the documentation
27
- // and/or other materials provided with the distribution.
28
- //
29
- // * The name of the copyright holders may not be used to endorse or promote products
30
- // derived from this software without specific prior written permission.
31
- //
32
- // This software is provided by the copyright holders and contributors "as is" and
33
- // any express or implied warranties, including, but not limited to, the implied
34
- // warranties of merchantability and fitness for a particular purpose are disclaimed.
35
- // In no event shall the Intel Corporation or contributors be liable for any direct,
36
- // indirect, incidental, special, exemplary, or consequential damages
37
- // (including, but not limited to, procurement of substitute goods or services;
38
- // loss of use, data, or profits; or business interruption) however caused
39
- // and on any theory of liability, whether in contract, strict liability,
40
- // or tort (including negligence or otherwise) arising in any way out of
41
- // the use of this software, even if advised of the possibility of such damage.
42
- //
43
- //M*/
44
-
45
- #ifndef OPENCV_CORE_UTILITY_H
46
- #define OPENCV_CORE_UTILITY_H
47
-
48
- #ifndef __cplusplus
49
- # error utility.hpp header must be compiled as C++
50
- #endif
51
-
52
- #if defined(check)
53
- # warning Detected Apple 'check' macro definition, it can cause build conflicts. Please, include this header before any Apple headers.
54
- #endif
55
-
56
- #include "opencv2/core.hpp"
57
- #include <ostream>
58
-
59
- #include <functional>
60
-
61
- #if !defined(_M_CEE)
62
- #include <mutex> // std::mutex, std::lock_guard
63
- #endif
64
-
65
- namespace cv
66
- {
67
-
68
- //! @addtogroup core_utils
69
- //! @{
70
-
71
- /** @brief Automatically Allocated Buffer Class
72
-
73
- The class is used for temporary buffers in functions and methods.
74
- If a temporary buffer is usually small (a few K's of memory),
75
- but its size depends on the parameters, it makes sense to create a small
76
- fixed-size array on stack and use it if it's large enough. If the required buffer size
77
- is larger than the fixed size, another buffer of sufficient size is allocated dynamically
78
- and released after the processing. Therefore, in typical cases, when the buffer size is small,
79
- there is no overhead associated with malloc()/free().
80
- At the same time, there is no limit on the size of processed data.
81
-
82
- This is what AutoBuffer does. The template takes 2 parameters - type of the buffer elements and
83
- the number of stack-allocated elements. Here is how the class is used:
84
-
85
- \code
86
- void my_func(const cv::Mat& m)
87
- {
88
- cv::AutoBuffer<float> buf(1000); // create automatic buffer containing 1000 floats
89
-
90
- buf.allocate(m.rows); // if m.rows <= 1000, the pre-allocated buffer is used,
91
- // otherwise the buffer of "m.rows" floats will be allocated
92
- // dynamically and deallocated in cv::AutoBuffer destructor
93
- ...
94
- }
95
- \endcode
96
- */
97
- #ifdef OPENCV_ENABLE_MEMORY_SANITIZER
98
- template<typename _Tp, size_t fixed_size = 0> class AutoBuffer
99
- #else
100
- template<typename _Tp, size_t fixed_size = 1024/sizeof(_Tp)+8> class AutoBuffer
101
- #endif
102
- {
103
- public:
104
- typedef _Tp value_type;
105
-
106
- //! the default constructor
107
- AutoBuffer();
108
- //! constructor taking the real buffer size
109
- explicit AutoBuffer(size_t _size);
110
-
111
- //! the copy constructor
112
- AutoBuffer(const AutoBuffer<_Tp, fixed_size>& buf);
113
- //! the assignment operator
114
- AutoBuffer<_Tp, fixed_size>& operator = (const AutoBuffer<_Tp, fixed_size>& buf);
115
-
116
- //! destructor. calls deallocate()
117
- ~AutoBuffer();
118
-
119
- //! allocates the new buffer of size _size. if the _size is small enough, stack-allocated buffer is used
120
- void allocate(size_t _size);
121
- //! deallocates the buffer if it was dynamically allocated
122
- void deallocate();
123
- //! resizes the buffer and preserves the content
124
- void resize(size_t _size);
125
- //! returns the current buffer size
126
- size_t size() const;
127
- //! returns pointer to the real buffer, stack-allocated or heap-allocated
128
- inline _Tp* data() { return ptr; }
129
- //! returns read-only pointer to the real buffer, stack-allocated or heap-allocated
130
- inline const _Tp* data() const { return ptr; }
131
-
132
- #if !defined(OPENCV_DISABLE_DEPRECATED_COMPATIBILITY) // use to .data() calls instead
133
- //! returns pointer to the real buffer, stack-allocated or heap-allocated
134
- operator _Tp* () { return ptr; }
135
- //! returns read-only pointer to the real buffer, stack-allocated or heap-allocated
136
- operator const _Tp* () const { return ptr; }
137
- #else
138
- //! returns a reference to the element at specified location. No bounds checking is performed in Release builds.
139
- inline _Tp& operator[] (size_t i) { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; }
140
- //! returns a reference to the element at specified location. No bounds checking is performed in Release builds.
141
- inline const _Tp& operator[] (size_t i) const { CV_DbgCheckLT(i, sz, "out of range"); return ptr[i]; }
142
- #endif
143
-
144
- protected:
145
- //! pointer to the real buffer, can point to buf if the buffer is small enough
146
- _Tp* ptr;
147
- //! size of the real buffer
148
- size_t sz;
149
- //! pre-allocated buffer. At least 1 element to confirm C++ standard requirements
150
- _Tp buf[(fixed_size > 0) ? fixed_size : 1];
151
- };
152
-
153
- /** @brief Sets/resets the break-on-error mode.
154
-
155
- When the break-on-error mode is set, the default error handler issues a hardware exception, which
156
- can make debugging more convenient.
157
-
158
- \return the previous state
159
- */
160
- CV_EXPORTS bool setBreakOnError(bool flag);
161
-
162
- extern "C" typedef int (*ErrorCallback)( int status, const char* func_name,
163
- const char* err_msg, const char* file_name,
164
- int line, void* userdata );
165
-
166
-
167
- /** @brief Sets the new error handler and the optional user data.
168
-
169
- The function sets the new error handler, called from cv::error().
170
-
171
- \param errCallback the new error handler. If NULL, the default error handler is used.
172
- \param userdata the optional user data pointer, passed to the callback.
173
- \param prevUserdata the optional output parameter where the previous user data pointer is stored
174
-
175
- \return the previous error handler
176
- */
177
- CV_EXPORTS ErrorCallback redirectError( ErrorCallback errCallback, void* userdata=0, void** prevUserdata=0);
178
-
179
- CV_EXPORTS String tempfile( const char* suffix = 0);
180
- CV_EXPORTS void glob(String pattern, std::vector<String>& result, bool recursive = false);
181
-
182
- /** @brief OpenCV will try to set the number of threads for the next parallel region.
183
-
184
- If threads == 0, OpenCV will disable threading optimizations and run all it's functions
185
- sequentially. Passing threads \< 0 will reset threads number to system default. This function must
186
- be called outside of parallel region.
187
-
188
- OpenCV will try to run its functions with specified threads number, but some behaviour differs from
189
- framework:
190
- - `TBB` - User-defined parallel constructions will run with the same threads number, if
191
- another is not specified. If later on user creates his own scheduler, OpenCV will use it.
192
- - `OpenMP` - No special defined behaviour.
193
- - `Concurrency` - If threads == 1, OpenCV will disable threading optimizations and run its
194
- functions sequentially.
195
- - `GCD` - Supports only values \<= 0.
196
- - `C=` - No special defined behaviour.
197
- @param nthreads Number of threads used by OpenCV.
198
- @sa getNumThreads, getThreadNum
199
- */
200
- CV_EXPORTS_W void setNumThreads(int nthreads);
201
-
202
- /** @brief Returns the number of threads used by OpenCV for parallel regions.
203
-
204
- Always returns 1 if OpenCV is built without threading support.
205
-
206
- The exact meaning of return value depends on the threading framework used by OpenCV library:
207
- - `TBB` - The number of threads, that OpenCV will try to use for parallel regions. If there is
208
- any tbb::thread_scheduler_init in user code conflicting with OpenCV, then function returns
209
- default number of threads used by TBB library.
210
- - `OpenMP` - An upper bound on the number of threads that could be used to form a new team.
211
- - `Concurrency` - The number of threads, that OpenCV will try to use for parallel regions.
212
- - `GCD` - Unsupported; returns the GCD thread pool limit (512) for compatibility.
213
- - `C=` - The number of threads, that OpenCV will try to use for parallel regions, if before
214
- called setNumThreads with threads \> 0, otherwise returns the number of logical CPUs,
215
- available for the process.
216
- @sa setNumThreads, getThreadNum
217
- */
218
- CV_EXPORTS_W int getNumThreads();
219
-
220
- /** @brief Returns the index of the currently executed thread within the current parallel region. Always
221
- returns 0 if called outside of parallel region.
222
-
223
- @deprecated Current implementation doesn't corresponding to this documentation.
224
-
225
- The exact meaning of the return value depends on the threading framework used by OpenCV library:
226
- - `TBB` - Unsupported with current 4.1 TBB release. Maybe will be supported in future.
227
- - `OpenMP` - The thread number, within the current team, of the calling thread.
228
- - `Concurrency` - An ID for the virtual processor that the current context is executing on (0
229
- for master thread and unique number for others, but not necessary 1,2,3,...).
230
- - `GCD` - System calling thread's ID. Never returns 0 inside parallel region.
231
- - `C=` - The index of the current parallel task.
232
- @sa setNumThreads, getNumThreads
233
- */
234
- CV_EXPORTS_W int getThreadNum();
235
-
236
- /** @brief Returns full configuration time cmake output.
237
-
238
- Returned value is raw cmake output including version control system revision, compiler version,
239
- compiler flags, enabled modules and third party libraries, etc. Output format depends on target
240
- architecture.
241
- */
242
- CV_EXPORTS_W const String& getBuildInformation();
243
-
244
- /** @brief Returns library version string
245
-
246
- For example "3.4.1-dev".
247
-
248
- @sa getMajorVersion, getMinorVersion, getRevisionVersion
249
- */
250
- CV_EXPORTS_W String getVersionString();
251
-
252
- /** @brief Returns major library version */
253
- CV_EXPORTS_W int getVersionMajor();
254
-
255
- /** @brief Returns minor library version */
256
- CV_EXPORTS_W int getVersionMinor();
257
-
258
- /** @brief Returns revision field of the library version */
259
- CV_EXPORTS_W int getVersionRevision();
260
-
261
- /** @brief Returns the number of ticks.
262
-
263
- The function returns the number of ticks after the certain event (for example, when the machine was
264
- turned on). It can be used to initialize RNG or to measure a function execution time by reading the
265
- tick count before and after the function call.
266
- @sa getTickFrequency, TickMeter
267
- */
268
- CV_EXPORTS_W int64 getTickCount();
269
-
270
- /** @brief Returns the number of ticks per second.
271
-
272
- The function returns the number of ticks per second. That is, the following code computes the
273
- execution time in seconds:
274
- @code
275
- double t = (double)getTickCount();
276
- // do something ...
277
- t = ((double)getTickCount() - t)/getTickFrequency();
278
- @endcode
279
- @sa getTickCount, TickMeter
280
- */
281
- CV_EXPORTS_W double getTickFrequency();
282
-
283
- /** @brief a Class to measure passing time.
284
-
285
- The class computes passing time by counting the number of ticks per second. That is, the following code computes the
286
- execution time in seconds:
287
- @snippet snippets/core_various.cpp TickMeter_total
288
-
289
- It is also possible to compute the average time over multiple runs:
290
- @snippet snippets/core_various.cpp TickMeter_average
291
-
292
- @sa getTickCount, getTickFrequency
293
- */
294
- class CV_EXPORTS_W TickMeter
295
- {
296
- public:
297
- //! the default constructor
298
- CV_WRAP TickMeter()
299
- {
300
- reset();
301
- }
302
-
303
- //! starts counting ticks.
304
- CV_WRAP void start()
305
- {
306
- startTime = cv::getTickCount();
307
- }
308
-
309
- //! stops counting ticks.
310
- CV_WRAP void stop()
311
- {
312
- int64 time = cv::getTickCount();
313
- if (startTime == 0)
314
- return;
315
- ++counter;
316
- sumTime += (time - startTime);
317
- startTime = 0;
318
- }
319
-
320
- //! returns counted ticks.
321
- CV_WRAP int64 getTimeTicks() const
322
- {
323
- return sumTime;
324
- }
325
-
326
- //! returns passed time in microseconds.
327
- CV_WRAP double getTimeMicro() const
328
- {
329
- return getTimeMilli()*1e3;
330
- }
331
-
332
- //! returns passed time in milliseconds.
333
- CV_WRAP double getTimeMilli() const
334
- {
335
- return getTimeSec()*1e3;
336
- }
337
-
338
- //! returns passed time in seconds.
339
- CV_WRAP double getTimeSec() const
340
- {
341
- return (double)getTimeTicks() / getTickFrequency();
342
- }
343
-
344
- //! returns internal counter value.
345
- CV_WRAP int64 getCounter() const
346
- {
347
- return counter;
348
- }
349
-
350
- //! returns average FPS (frames per second) value.
351
- CV_WRAP double getFPS() const
352
- {
353
- const double sec = getTimeSec();
354
- if (sec < DBL_EPSILON)
355
- return 0.;
356
- return counter / sec;
357
- }
358
-
359
- //! returns average time in seconds
360
- CV_WRAP double getAvgTimeSec() const
361
- {
362
- if (counter <= 0)
363
- return 0.;
364
- return getTimeSec() / counter;
365
- }
366
-
367
- //! returns average time in milliseconds
368
- CV_WRAP double getAvgTimeMilli() const
369
- {
370
- return getAvgTimeSec() * 1e3;
371
- }
372
-
373
- //! resets internal values.
374
- CV_WRAP void reset()
375
- {
376
- startTime = 0;
377
- sumTime = 0;
378
- counter = 0;
379
- }
380
-
381
- private:
382
- int64 counter;
383
- int64 sumTime;
384
- int64 startTime;
385
- };
386
-
387
- /** @brief output operator
388
- @code
389
- TickMeter tm;
390
- tm.start();
391
- // do something ...
392
- tm.stop();
393
- std::cout << tm;
394
- @endcode
395
- */
396
-
397
- static inline
398
- std::ostream& operator << (std::ostream& out, const TickMeter& tm)
399
- {
400
- return out << tm.getTimeSec() << "sec";
401
- }
402
-
403
- /** @brief Returns the number of CPU ticks.
404
-
405
- The function returns the current number of CPU ticks on some architectures (such as x86, x64,
406
- PowerPC). On other platforms the function is equivalent to getTickCount. It can also be used for
407
- very accurate time measurements, as well as for RNG initialization. Note that in case of multi-CPU
408
- systems a thread, from which getCPUTickCount is called, can be suspended and resumed at another CPU
409
- with its own counter. So, theoretically (and practically) the subsequent calls to the function do
410
- not necessary return the monotonously increasing values. Also, since a modern CPU varies the CPU
411
- frequency depending on the load, the number of CPU clocks spent in some code cannot be directly
412
- converted to time units. Therefore, getTickCount is generally a preferable solution for measuring
413
- execution time.
414
- */
415
- CV_EXPORTS_W int64 getCPUTickCount();
416
-
417
- /** @brief Returns true if the specified feature is supported by the host hardware.
418
-
419
- The function returns true if the host hardware supports the specified feature. When user calls
420
- setUseOptimized(false), the subsequent calls to checkHardwareSupport() will return false until
421
- setUseOptimized(true) is called. This way user can dynamically switch on and off the optimized code
422
- in OpenCV.
423
- @param feature The feature of interest, one of cv::CpuFeatures
424
- */
425
- CV_EXPORTS_W bool checkHardwareSupport(int feature);
426
-
427
- /** @brief Returns feature name by ID
428
-
429
- Returns empty string if feature is not defined
430
- */
431
- CV_EXPORTS_W String getHardwareFeatureName(int feature);
432
-
433
- /** @brief Returns list of CPU features enabled during compilation.
434
-
435
- Returned value is a string containing space separated list of CPU features with following markers:
436
-
437
- - no markers - baseline features
438
- - prefix `*` - features enabled in dispatcher
439
- - suffix `?` - features enabled but not available in HW
440
-
441
- Example: `SSE SSE2 SSE3 *SSE4.1 *SSE4.2 *FP16 *AVX *AVX2 *AVX512-SKX?`
442
- */
443
- CV_EXPORTS_W std::string getCPUFeaturesLine();
444
-
445
- /** @brief Returns the number of logical CPUs available for the process.
446
- */
447
- CV_EXPORTS_W int getNumberOfCPUs();
448
-
449
-
450
- /** @brief Aligns a pointer to the specified number of bytes.
451
-
452
- The function returns the aligned pointer of the same type as the input pointer:
453
- \f[\texttt{(_Tp*)(((size_t)ptr + n-1) & -n)}\f]
454
- @param ptr Aligned pointer.
455
- @param n Alignment size that must be a power of two.
456
- */
457
- template<typename _Tp> static inline _Tp* alignPtr(_Tp* ptr, int n=(int)sizeof(_Tp))
458
- {
459
- CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2
460
- return (_Tp*)(((size_t)ptr + n-1) & -n);
461
- }
462
-
463
- /** @brief Aligns a buffer size to the specified number of bytes.
464
-
465
- The function returns the minimum number that is greater than or equal to sz and is divisible by n :
466
- \f[\texttt{(sz + n-1) & -n}\f]
467
- @param sz Buffer size to align.
468
- @param n Alignment size that must be a power of two.
469
- */
470
- static inline size_t alignSize(size_t sz, int n)
471
- {
472
- CV_DbgAssert((n & (n - 1)) == 0); // n is a power of 2
473
- return (sz + n-1) & -n;
474
- }
475
-
476
- /** @brief Integer division with result round up.
477
-
478
- Use this function instead of `ceil((float)a / b)` expressions.
479
-
480
- @sa alignSize
481
- */
482
- static inline int divUp(int a, unsigned int b)
483
- {
484
- CV_DbgAssert(a >= 0);
485
- return (a + b - 1) / b;
486
- }
487
- /** @overload */
488
- static inline size_t divUp(size_t a, unsigned int b)
489
- {
490
- return (a + b - 1) / b;
491
- }
492
-
493
- /** @brief Round first value up to the nearest multiple of second value.
494
-
495
- Use this function instead of `ceil((float)a / b) * b` expressions.
496
-
497
- @sa divUp
498
- */
499
- static inline int roundUp(int a, unsigned int b)
500
- {
501
- CV_DbgAssert(a >= 0);
502
- return a + b - 1 - (a + b -1) % b;
503
- }
504
- /** @overload */
505
- static inline size_t roundUp(size_t a, unsigned int b)
506
- {
507
- return a + b - 1 - (a + b - 1) % b;
508
- }
509
-
510
- /** @brief Alignment check of passed values
511
-
512
- Usage: `isAligned<sizeof(int)>(...)`
513
-
514
- @note Alignment(N) must be a power of 2 (2**k, 2^k)
515
- */
516
- template<int N, typename T> static inline
517
- bool isAligned(const T& data)
518
- {
519
- CV_StaticAssert((N & (N - 1)) == 0, ""); // power of 2
520
- return (((size_t)data) & (N - 1)) == 0;
521
- }
522
- /** @overload */
523
- template<int N> static inline
524
- bool isAligned(const void* p1)
525
- {
526
- return isAligned<N>((size_t)p1);
527
- }
528
- /** @overload */
529
- template<int N> static inline
530
- bool isAligned(const void* p1, const void* p2)
531
- {
532
- return isAligned<N>(((size_t)p1)|((size_t)p2));
533
- }
534
- /** @overload */
535
- template<int N> static inline
536
- bool isAligned(const void* p1, const void* p2, const void* p3)
537
- {
538
- return isAligned<N>(((size_t)p1)|((size_t)p2)|((size_t)p3));
539
- }
540
- /** @overload */
541
- template<int N> static inline
542
- bool isAligned(const void* p1, const void* p2, const void* p3, const void* p4)
543
- {
544
- return isAligned<N>(((size_t)p1)|((size_t)p2)|((size_t)p3)|((size_t)p4));
545
- }
546
-
547
- /** @brief Enables or disables the optimized code.
548
-
549
- The function can be used to dynamically turn on and off optimized dispatched code (code that uses SSE4.2, AVX/AVX2,
550
- and other instructions on the platforms that support it). It sets a global flag that is further
551
- checked by OpenCV functions. Since the flag is not checked in the inner OpenCV loops, it is only
552
- safe to call the function on the very top level in your application where you can be sure that no
553
- other OpenCV function is currently executed.
554
-
555
- By default, the optimized code is enabled unless you disable it in CMake. The current status can be
556
- retrieved using useOptimized.
557
- @param onoff The boolean flag specifying whether the optimized code should be used (onoff=true)
558
- or not (onoff=false).
559
- */
560
- CV_EXPORTS_W void setUseOptimized(bool onoff);
561
-
562
- /** @brief Returns the status of optimized code usage.
563
-
564
- The function returns true if the optimized code is enabled. Otherwise, it returns false.
565
- */
566
- CV_EXPORTS_W bool useOptimized();
567
-
568
- static inline size_t getElemSize(int type) { return (size_t)CV_ELEM_SIZE(type); }
569
-
570
- /////////////////////////////// Parallel Primitives //////////////////////////////////
571
-
572
- /** @brief Base class for parallel data processors
573
-
574
- @ingroup core_parallel
575
- */
576
- class CV_EXPORTS ParallelLoopBody
577
- {
578
- public:
579
- virtual ~ParallelLoopBody();
580
- virtual void operator() (const Range& range) const = 0;
581
- };
582
-
583
- /** @brief Parallel data processor
584
-
585
- @ingroup core_parallel
586
- */
587
- CV_EXPORTS void parallel_for_(const Range& range, const ParallelLoopBody& body, double nstripes=-1.);
588
-
589
- //! @ingroup core_parallel
590
- class ParallelLoopBodyLambdaWrapper : public ParallelLoopBody
591
- {
592
- private:
593
- std::function<void(const Range&)> m_functor;
594
- public:
595
- inline
596
- ParallelLoopBodyLambdaWrapper(std::function<void(const Range&)> functor)
597
- : m_functor(functor)
598
- {
599
- // nothing
600
- }
601
-
602
- virtual void operator() (const cv::Range& range) const CV_OVERRIDE
603
- {
604
- m_functor(range);
605
- }
606
- };
607
-
608
- //! @ingroup core_parallel
609
- static inline
610
- void parallel_for_(const Range& range, std::function<void(const Range&)> functor, double nstripes=-1.)
611
- {
612
- parallel_for_(range, ParallelLoopBodyLambdaWrapper(functor), nstripes);
613
- }
614
-
615
-
616
- /////////////////////////////// forEach method of cv::Mat ////////////////////////////
617
- template<typename _Tp, typename Functor> inline
618
- void Mat::forEach_impl(const Functor& operation) {
619
- if (false) {
620
- operation(*reinterpret_cast<_Tp*>(0), reinterpret_cast<int*>(0));
621
- // If your compiler fails in this line.
622
- // Please check that your functor signature is
623
- // (_Tp&, const int*) <- multi-dimensional
624
- // or (_Tp&, void*) <- in case you don't need current idx.
625
- }
626
-
627
- CV_Assert(!empty());
628
- CV_Assert(this->total() / this->size[this->dims - 1] <= INT_MAX);
629
- const int LINES = static_cast<int>(this->total() / this->size[this->dims - 1]);
630
-
631
- class PixelOperationWrapper :public ParallelLoopBody
632
- {
633
- public:
634
- PixelOperationWrapper(Mat_<_Tp>* const frame, const Functor& _operation)
635
- : mat(frame), op(_operation) {}
636
- virtual ~PixelOperationWrapper(){}
637
- // ! Overloaded virtual operator
638
- // convert range call to row call.
639
- virtual void operator()(const Range &range) const CV_OVERRIDE
640
- {
641
- const int DIMS = mat->dims;
642
- const int COLS = mat->size[DIMS - 1];
643
- if (DIMS <= 2) {
644
- for (int row = range.start; row < range.end; ++row) {
645
- this->rowCall2(row, COLS);
646
- }
647
- } else {
648
- std::vector<int> idx(DIMS); /// idx is modified in this->rowCall
649
- idx[DIMS - 2] = range.start - 1;
650
-
651
- for (int line_num = range.start; line_num < range.end; ++line_num) {
652
- idx[DIMS - 2]++;
653
- for (int i = DIMS - 2; i >= 0; --i) {
654
- if (idx[i] >= mat->size[i]) {
655
- idx[i - 1] += idx[i] / mat->size[i];
656
- idx[i] %= mat->size[i];
657
- continue; // carry-over;
658
- }
659
- else {
660
- break;
661
- }
662
- }
663
- this->rowCall(&idx[0], COLS, DIMS);
664
- }
665
- }
666
- }
667
- private:
668
- Mat_<_Tp>* const mat;
669
- const Functor op;
670
- // ! Call operator for each elements in this row.
671
- inline void rowCall(int* const idx, const int COLS, const int DIMS) const {
672
- int &col = idx[DIMS - 1];
673
- col = 0;
674
- _Tp* pixel = &(mat->template at<_Tp>(idx));
675
-
676
- while (col < COLS) {
677
- op(*pixel, const_cast<const int*>(idx));
678
- pixel++; col++;
679
- }
680
- col = 0;
681
- }
682
- // ! Call operator for each elements in this row. 2d mat special version.
683
- inline void rowCall2(const int row, const int COLS) const {
684
- union Index{
685
- int body[2];
686
- operator const int*() const {
687
- return reinterpret_cast<const int*>(this);
688
- }
689
- int& operator[](const int i) {
690
- return body[i];
691
- }
692
- } idx = {{row, 0}};
693
- // Special union is needed to avoid
694
- // "error: array subscript is above array bounds [-Werror=array-bounds]"
695
- // when call the functor `op` such that access idx[3].
696
-
697
- _Tp* pixel = &(mat->template at<_Tp>(idx));
698
- const _Tp* const pixel_end = pixel + COLS;
699
- while(pixel < pixel_end) {
700
- op(*pixel++, static_cast<const int*>(idx));
701
- idx[1]++;
702
- }
703
- }
704
- PixelOperationWrapper& operator=(const PixelOperationWrapper &) {
705
- CV_Assert(false);
706
- // We can not remove this implementation because Visual Studio warning C4822.
707
- return *this;
708
- }
709
- };
710
-
711
- parallel_for_(cv::Range(0, LINES), PixelOperationWrapper(reinterpret_cast<Mat_<_Tp>*>(this), operation));
712
- }
713
-
714
- /////////////////////////// Synchronization Primitives ///////////////////////////////
715
-
716
- #if !defined(_M_CEE)
717
- #ifndef OPENCV_DISABLE_THREAD_SUPPORT
718
- typedef std::recursive_mutex Mutex;
719
- typedef std::lock_guard<cv::Mutex> AutoLock;
720
- #else // OPENCV_DISABLE_THREAD_SUPPORT
721
- // Custom (failing) implementation of `std::recursive_mutex`.
722
- struct Mutex {
723
- void lock(){
724
- CV_Error(cv::Error::StsNotImplemented,
725
- "cv::Mutex is disabled by OPENCV_DISABLE_THREAD_SUPPORT=ON");
726
- }
727
- void unlock(){
728
- CV_Error(cv::Error::StsNotImplemented,
729
- "cv::Mutex is disabled by OPENCV_DISABLE_THREAD_SUPPORT=ON");
730
- }
731
- };
732
- // Stub for cv::AutoLock when threads are disabled.
733
- struct AutoLock {
734
- AutoLock(Mutex &) { }
735
- };
736
- #endif // OPENCV_DISABLE_THREAD_SUPPORT
737
- #endif // !defined(_M_CEE)
738
-
739
-
740
- /** @brief Designed for command line parsing
741
-
742
- The sample below demonstrates how to use CommandLineParser:
743
- @code
744
- CommandLineParser parser(argc, argv, keys);
745
- parser.about("Application name v1.0.0");
746
-
747
- if (parser.has("help"))
748
- {
749
- parser.printMessage();
750
- return 0;
751
- }
752
-
753
- int N = parser.get<int>("N");
754
- double fps = parser.get<double>("fps");
755
- String path = parser.get<String>("path");
756
-
757
- use_time_stamp = parser.has("timestamp");
758
-
759
- String img1 = parser.get<String>(0);
760
- String img2 = parser.get<String>(1);
761
-
762
- int repeat = parser.get<int>(2);
763
-
764
- if (!parser.check())
765
- {
766
- parser.printErrors();
767
- return 0;
768
- }
769
- @endcode
770
-
771
- ### Keys syntax
772
-
773
- The keys parameter is a string containing several blocks, each one is enclosed in curly braces and
774
- describes one argument. Each argument contains three parts separated by the `|` symbol:
775
-
776
- -# argument names is a space-separated list of option synonyms (to mark argument as positional, prefix it with the `@` symbol)
777
- -# default value will be used if the argument was not provided (can be empty)
778
- -# help message (can be empty)
779
-
780
- For example:
781
-
782
- @code{.cpp}
783
- const String keys =
784
- "{help h usage ? | | print this message }"
785
- "{@image1 | | image1 for compare }"
786
- "{@image2 |<none>| image2 for compare }"
787
- "{@repeat |1 | number }"
788
- "{path |. | path to file }"
789
- "{fps | -1.0 | fps for output video }"
790
- "{N count |100 | count of objects }"
791
- "{ts timestamp | | use time stamp }"
792
- ;
793
- }
794
- @endcode
795
-
796
- Note that there are no default values for `help` and `timestamp` so we can check their presence using the `has()` method.
797
- Arguments with default values are considered to be always present. Use the `get()` method in these cases to check their
798
- actual value instead.
799
-
800
- String keys like `get<String>("@image1")` return the empty string `""` by default - even with an empty default value.
801
- Use the special `<none>` default value to enforce that the returned string must not be empty. (like in `get<String>("@image2")`)
802
-
803
- ### Usage
804
-
805
- For the described keys:
806
-
807
- @code{.sh}
808
- # Good call (3 positional parameters: image1, image2 and repeat; N is 200, ts is true)
809
- $ ./app -N=200 1.png 2.jpg 19 -ts
810
-
811
- # Bad call
812
- $ ./app -fps=aaa
813
- ERRORS:
814
- Parameter 'fps': can not convert: [aaa] to [double]
815
- @endcode
816
- */
817
- class CV_EXPORTS CommandLineParser
818
- {
819
- public:
820
-
821
- /** @brief Constructor
822
-
823
- Initializes command line parser object
824
-
825
- @param argc number of command line arguments (from main())
826
- @param argv array of command line arguments (from main())
827
- @param keys string describing acceptable command line parameters (see class description for syntax)
828
- */
829
- CommandLineParser(int argc, const char* const argv[], const String& keys);
830
-
831
- /** @brief Copy constructor */
832
- CommandLineParser(const CommandLineParser& parser);
833
-
834
- /** @brief Assignment operator */
835
- CommandLineParser& operator = (const CommandLineParser& parser);
836
-
837
- /** @brief Destructor */
838
- ~CommandLineParser();
839
-
840
- /** @brief Returns application path
841
-
842
- This method returns the path to the executable from the command line (`argv[0]`).
843
-
844
- For example, if the application has been started with such a command:
845
- @code{.sh}
846
- $ ./bin/my-executable
847
- @endcode
848
- this method will return `./bin`.
849
- */
850
- String getPathToApplication() const;
851
-
852
- /** @brief Access arguments by name
853
-
854
- Returns argument converted to selected type. If the argument is not known or can not be
855
- converted to selected type, the error flag is set (can be checked with @ref check).
856
-
857
- For example, define:
858
- @code{.cpp}
859
- String keys = "{N count||}";
860
- @endcode
861
-
862
- Call:
863
- @code{.sh}
864
- $ ./my-app -N=20
865
- # or
866
- $ ./my-app --count=20
867
- @endcode
868
-
869
- Access:
870
- @code{.cpp}
871
- int N = parser.get<int>("N");
872
- @endcode
873
-
874
- @param name name of the argument
875
- @param space_delete remove spaces from the left and right of the string
876
- @tparam T the argument will be converted to this type if possible
877
-
878
- @note You can access positional arguments by their `@`-prefixed name:
879
- @code{.cpp}
880
- parser.get<String>("@image");
881
- @endcode
882
- */
883
- template <typename T>
884
- T get(const String& name, bool space_delete = true) const
885
- {
886
- T val = T();
887
- getByName(name, space_delete, ParamType<T>::type, (void*)&val);
888
- return val;
889
- }
890
-
891
- /** @brief Access positional arguments by index
892
-
893
- Returns argument converted to selected type. Indexes are counted from zero.
894
-
895
- For example, define:
896
- @code{.cpp}
897
- String keys = "{@arg1||}{@arg2||}"
898
- @endcode
899
-
900
- Call:
901
- @code{.sh}
902
- ./my-app abc qwe
903
- @endcode
904
-
905
- Access arguments:
906
- @code{.cpp}
907
- String val_1 = parser.get<String>(0); // returns "abc", arg1
908
- String val_2 = parser.get<String>(1); // returns "qwe", arg2
909
- @endcode
910
-
911
- @param index index of the argument
912
- @param space_delete remove spaces from the left and right of the string
913
- @tparam T the argument will be converted to this type if possible
914
- */
915
- template <typename T>
916
- T get(int index, bool space_delete = true) const
917
- {
918
- T val = T();
919
- getByIndex(index, space_delete, ParamType<T>::type, (void*)&val);
920
- return val;
921
- }
922
-
923
- /** @brief Check if field was provided in the command line
924
-
925
- @param name argument name to check
926
- */
927
- bool has(const String& name) const;
928
-
929
- /** @brief Check for parsing errors
930
-
931
- Returns false if error occurred while accessing the parameters (bad conversion, missing arguments,
932
- etc.). Call @ref printErrors to print error messages list.
933
- */
934
- bool check() const;
935
-
936
- /** @brief Set the about message
937
-
938
- The about message will be shown when @ref printMessage is called, right before arguments table.
939
- */
940
- void about(const String& message);
941
-
942
- /** @brief Print help message
943
-
944
- This method will print standard help message containing the about message and arguments description.
945
-
946
- @sa about
947
- */
948
- void printMessage() const;
949
-
950
- /** @brief Print list of errors occurred
951
-
952
- @sa check
953
- */
954
- void printErrors() const;
955
-
956
- protected:
957
- void getByName(const String& name, bool space_delete, Param type, void* dst) const;
958
- void getByIndex(int index, bool space_delete, Param type, void* dst) const;
959
-
960
- struct Impl;
961
- Impl* impl;
962
- };
963
-
964
- //! @} core_utils
965
-
966
- //! @cond IGNORED
967
-
968
- /////////////////////////////// AutoBuffer implementation ////////////////////////////////////////
969
-
970
- template<typename _Tp, size_t fixed_size> inline
971
- AutoBuffer<_Tp, fixed_size>::AutoBuffer()
972
- {
973
- ptr = buf;
974
- sz = fixed_size;
975
- }
976
-
977
- template<typename _Tp, size_t fixed_size> inline
978
- AutoBuffer<_Tp, fixed_size>::AutoBuffer(size_t _size)
979
- {
980
- ptr = buf;
981
- sz = fixed_size;
982
- allocate(_size);
983
- }
984
-
985
- template<typename _Tp, size_t fixed_size> inline
986
- AutoBuffer<_Tp, fixed_size>::AutoBuffer(const AutoBuffer<_Tp, fixed_size>& abuf )
987
- {
988
- ptr = buf;
989
- sz = fixed_size;
990
- allocate(abuf.size());
991
- for( size_t i = 0; i < sz; i++ )
992
- ptr[i] = abuf.ptr[i];
993
- }
994
-
995
- template<typename _Tp, size_t fixed_size> inline AutoBuffer<_Tp, fixed_size>&
996
- AutoBuffer<_Tp, fixed_size>::operator = (const AutoBuffer<_Tp, fixed_size>& abuf)
997
- {
998
- if( this != &abuf )
999
- {
1000
- deallocate();
1001
- allocate(abuf.size());
1002
- for( size_t i = 0; i < sz; i++ )
1003
- ptr[i] = abuf.ptr[i];
1004
- }
1005
- return *this;
1006
- }
1007
-
1008
- template<typename _Tp, size_t fixed_size> inline
1009
- AutoBuffer<_Tp, fixed_size>::~AutoBuffer()
1010
- { deallocate(); }
1011
-
1012
- template<typename _Tp, size_t fixed_size> inline void
1013
- AutoBuffer<_Tp, fixed_size>::allocate(size_t _size)
1014
- {
1015
- if(_size <= sz)
1016
- {
1017
- sz = _size;
1018
- return;
1019
- }
1020
- deallocate();
1021
- sz = _size;
1022
- if(_size > fixed_size)
1023
- {
1024
- ptr = new _Tp[_size];
1025
- }
1026
- }
1027
-
1028
- template<typename _Tp, size_t fixed_size> inline void
1029
- AutoBuffer<_Tp, fixed_size>::deallocate()
1030
- {
1031
- if( ptr != buf )
1032
- {
1033
- delete[] ptr;
1034
- ptr = buf;
1035
- sz = fixed_size;
1036
- }
1037
- }
1038
-
1039
- template<typename _Tp, size_t fixed_size> inline void
1040
- AutoBuffer<_Tp, fixed_size>::resize(size_t _size)
1041
- {
1042
- if(_size <= sz)
1043
- {
1044
- sz = _size;
1045
- return;
1046
- }
1047
- size_t i, prevsize = sz, minsize = MIN(prevsize, _size);
1048
- _Tp* prevptr = ptr;
1049
-
1050
- ptr = _size > fixed_size ? new _Tp[_size] : buf;
1051
- sz = _size;
1052
-
1053
- if( ptr != prevptr )
1054
- for( i = 0; i < minsize; i++ )
1055
- ptr[i] = prevptr[i];
1056
- for( i = prevsize; i < _size; i++ )
1057
- ptr[i] = _Tp();
1058
-
1059
- if( prevptr != buf )
1060
- delete[] prevptr;
1061
- }
1062
-
1063
- template<typename _Tp, size_t fixed_size> inline size_t
1064
- AutoBuffer<_Tp, fixed_size>::size() const
1065
- { return sz; }
1066
-
1067
- //! @endcond
1068
-
1069
-
1070
- // Basic Node class for tree building
1071
- template<class OBJECT>
1072
- class CV_EXPORTS Node
1073
- {
1074
- public:
1075
- Node()
1076
- {
1077
- m_pParent = 0;
1078
- }
1079
- Node(OBJECT& payload) : m_payload(payload)
1080
- {
1081
- m_pParent = 0;
1082
- }
1083
- ~Node()
1084
- {
1085
- removeChilds();
1086
- if (m_pParent)
1087
- {
1088
- int idx = m_pParent->findChild(this);
1089
- if (idx >= 0)
1090
- m_pParent->m_childs.erase(m_pParent->m_childs.begin() + idx);
1091
- }
1092
- }
1093
-
1094
- Node<OBJECT>* findChild(OBJECT& payload) const
1095
- {
1096
- for(size_t i = 0; i < this->m_childs.size(); i++)
1097
- {
1098
- if(this->m_childs[i]->m_payload == payload)
1099
- return this->m_childs[i];
1100
- }
1101
- return NULL;
1102
- }
1103
-
1104
- int findChild(Node<OBJECT> *pNode) const
1105
- {
1106
- for (size_t i = 0; i < this->m_childs.size(); i++)
1107
- {
1108
- if(this->m_childs[i] == pNode)
1109
- return (int)i;
1110
- }
1111
- return -1;
1112
- }
1113
-
1114
- void addChild(Node<OBJECT> *pNode)
1115
- {
1116
- if(!pNode)
1117
- return;
1118
-
1119
- CV_Assert(pNode->m_pParent == 0);
1120
- pNode->m_pParent = this;
1121
- this->m_childs.push_back(pNode);
1122
- }
1123
-
1124
- void removeChilds()
1125
- {
1126
- for(size_t i = 0; i < m_childs.size(); i++)
1127
- {
1128
- m_childs[i]->m_pParent = 0; // avoid excessive parent vector trimming
1129
- delete m_childs[i];
1130
- }
1131
- m_childs.clear();
1132
- }
1133
-
1134
- int getDepth()
1135
- {
1136
- int count = 0;
1137
- Node *pParent = m_pParent;
1138
- while(pParent) count++, pParent = pParent->m_pParent;
1139
- return count;
1140
- }
1141
-
1142
- public:
1143
- OBJECT m_payload;
1144
- Node<OBJECT>* m_pParent;
1145
- std::vector<Node<OBJECT>*> m_childs;
1146
- };
1147
-
1148
-
1149
- namespace samples {
1150
-
1151
- //! @addtogroup core_utils_samples
1152
- // This section describes utility functions for OpenCV samples.
1153
- //
1154
- // @note Implementation of these utilities is not thread-safe.
1155
- //
1156
- //! @{
1157
-
1158
- /** @brief Try to find requested data file
1159
-
1160
- Search directories:
1161
-
1162
- 1. Directories passed via `addSamplesDataSearchPath()`
1163
- 2. OPENCV_SAMPLES_DATA_PATH_HINT environment variable
1164
- 3. OPENCV_SAMPLES_DATA_PATH environment variable
1165
- If parameter value is not empty and nothing is found then stop searching.
1166
- 4. Detects build/install path based on:
1167
- a. current working directory (CWD)
1168
- b. and/or binary module location (opencv_core/opencv_world, doesn't work with static linkage)
1169
- 5. Scan `<source>/{,data,samples/data}` directories if build directory is detected or the current directory is in source tree.
1170
- 6. Scan `<install>/share/OpenCV` directory if install directory is detected.
1171
-
1172
- @see cv::utils::findDataFile
1173
-
1174
- @param relative_path Relative path to data file
1175
- @param required Specify "file not found" handling.
1176
- If true, function prints information message and raises cv::Exception.
1177
- If false, function returns empty result
1178
- @param silentMode Disables messages
1179
- @return Returns path (absolute or relative to the current directory) or empty string if file is not found
1180
- */
1181
- CV_EXPORTS_W cv::String findFile(const cv::String& relative_path, bool required = true, bool silentMode = false);
1182
-
1183
- CV_EXPORTS_W cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode = false);
1184
-
1185
- inline cv::String findFileOrKeep(const cv::String& relative_path, bool silentMode)
1186
- {
1187
- cv::String res = findFile(relative_path, false, silentMode);
1188
- if (res.empty())
1189
- return relative_path;
1190
- return res;
1191
- }
1192
-
1193
- /** @brief Override search data path by adding new search location
1194
-
1195
- Use this only to override default behavior
1196
- Passed paths are used in LIFO order.
1197
-
1198
- @param path Path to used samples data
1199
- */
1200
- CV_EXPORTS_W void addSamplesDataSearchPath(const cv::String& path);
1201
-
1202
- /** @brief Append samples search data sub directory
1203
-
1204
- General usage is to add OpenCV modules name (`<opencv_contrib>/modules/<name>/samples/data` -> `<name>/samples/data` + `modules/<name>/samples/data`).
1205
- Passed subdirectories are used in LIFO order.
1206
-
1207
- @param subdir samples data sub directory
1208
- */
1209
- CV_EXPORTS_W void addSamplesDataSearchSubDirectory(const cv::String& subdir);
1210
-
1211
- //! @}
1212
- } // namespace samples
1213
-
1214
- namespace utils {
1215
-
1216
- CV_EXPORTS int getThreadID();
1217
-
1218
- } // namespace
1219
-
1220
- } //namespace cv
1221
-
1222
- #ifdef CV_COLLECT_IMPL_DATA
1223
- #include "opencv2/core/utils/instrumentation.hpp"
1224
- #else
1225
- /// Collect implementation data on OpenCV function call. Requires ENABLE_IMPL_COLLECTION build option.
1226
- #define CV_IMPL_ADD(impl)
1227
- #endif
1228
-
1229
- #endif //OPENCV_CORE_UTILITY_H