node-native-win-utils 1.3.4 → 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 (191) hide show
  1. package/README.md +30 -83
  2. package/binding.gyp +3 -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} +49 -17
  8. package/dist/{index.d.ts → index.d.cts} +25 -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 +22 -9
  15. package/prebuilds/win32-x64/node-native-win-utils.node +0 -0
  16. package/prebuilds/win32-x64/tesseract.dll +0 -0
  17. package/prebuilds/win32-x64/tiff.dll +0 -0
  18. package/src/cpp/keyboard.cpp +141 -140
  19. package/src/cpp/main.cpp +11 -3
  20. package/src/cpp/{capturewindow.cpp → screenshot.cpp} +174 -2
  21. package/src/cpp/tesseract.cpp +49 -0
  22. package/src/dirnameLocal.mts +3 -0
  23. package/src/index.mts +454 -0
  24. package/src/keyCodes.mts +203 -0
  25. package/include/opencv2/core/affine.hpp +0 -678
  26. package/include/opencv2/core/async.hpp +0 -105
  27. package/include/opencv2/core/base.hpp +0 -664
  28. package/include/opencv2/core/bindings_utils.hpp +0 -325
  29. package/include/opencv2/core/bufferpool.hpp +0 -40
  30. package/include/opencv2/core/check.hpp +0 -170
  31. package/include/opencv2/core/core.hpp +0 -48
  32. package/include/opencv2/core/core_c.h +0 -3128
  33. package/include/opencv2/core/cuda/block.hpp +0 -211
  34. package/include/opencv2/core/cuda/border_interpolate.hpp +0 -722
  35. package/include/opencv2/core/cuda/color.hpp +0 -309
  36. package/include/opencv2/core/cuda/common.hpp +0 -131
  37. package/include/opencv2/core/cuda/datamov_utils.hpp +0 -113
  38. package/include/opencv2/core/cuda/detail/color_detail.hpp +0 -2018
  39. package/include/opencv2/core/cuda/detail/reduce.hpp +0 -365
  40. package/include/opencv2/core/cuda/detail/reduce_key_val.hpp +0 -502
  41. package/include/opencv2/core/cuda/detail/transform_detail.hpp +0 -392
  42. package/include/opencv2/core/cuda/detail/type_traits_detail.hpp +0 -191
  43. package/include/opencv2/core/cuda/detail/vec_distance_detail.hpp +0 -121
  44. package/include/opencv2/core/cuda/dynamic_smem.hpp +0 -88
  45. package/include/opencv2/core/cuda/emulation.hpp +0 -269
  46. package/include/opencv2/core/cuda/filters.hpp +0 -293
  47. package/include/opencv2/core/cuda/funcattrib.hpp +0 -79
  48. package/include/opencv2/core/cuda/functional.hpp +0 -805
  49. package/include/opencv2/core/cuda/limits.hpp +0 -128
  50. package/include/opencv2/core/cuda/reduce.hpp +0 -209
  51. package/include/opencv2/core/cuda/saturate_cast.hpp +0 -292
  52. package/include/opencv2/core/cuda/scan.hpp +0 -258
  53. package/include/opencv2/core/cuda/simd_functions.hpp +0 -869
  54. package/include/opencv2/core/cuda/transform.hpp +0 -75
  55. package/include/opencv2/core/cuda/type_traits.hpp +0 -90
  56. package/include/opencv2/core/cuda/utility.hpp +0 -230
  57. package/include/opencv2/core/cuda/vec_distance.hpp +0 -232
  58. package/include/opencv2/core/cuda/vec_math.hpp +0 -923
  59. package/include/opencv2/core/cuda/vec_traits.hpp +0 -288
  60. package/include/opencv2/core/cuda/warp.hpp +0 -139
  61. package/include/opencv2/core/cuda/warp_reduce.hpp +0 -76
  62. package/include/opencv2/core/cuda/warp_shuffle.hpp +0 -162
  63. package/include/opencv2/core/cuda.hpp +0 -1279
  64. package/include/opencv2/core/cuda.inl.hpp +0 -763
  65. package/include/opencv2/core/cuda_stream_accessor.hpp +0 -86
  66. package/include/opencv2/core/cuda_types.hpp +0 -144
  67. package/include/opencv2/core/cv_cpu_dispatch.h +0 -381
  68. package/include/opencv2/core/cv_cpu_helper.h +0 -550
  69. package/include/opencv2/core/cvdef.h +0 -973
  70. package/include/opencv2/core/cvstd.hpp +0 -190
  71. package/include/opencv2/core/cvstd.inl.hpp +0 -197
  72. package/include/opencv2/core/cvstd_wrapper.hpp +0 -154
  73. package/include/opencv2/core/detail/async_promise.hpp +0 -71
  74. package/include/opencv2/core/detail/dispatch_helper.impl.hpp +0 -49
  75. package/include/opencv2/core/detail/exception_ptr.hpp +0 -27
  76. package/include/opencv2/core/directx.hpp +0 -184
  77. package/include/opencv2/core/dualquaternion.hpp +0 -979
  78. package/include/opencv2/core/dualquaternion.inl.hpp +0 -487
  79. package/include/opencv2/core/eigen.hpp +0 -402
  80. package/include/opencv2/core/fast_math.hpp +0 -433
  81. package/include/opencv2/core/hal/hal.hpp +0 -256
  82. package/include/opencv2/core/hal/interface.h +0 -190
  83. package/include/opencv2/core/hal/intrin.hpp +0 -939
  84. package/include/opencv2/core/hal/intrin_avx.hpp +0 -3177
  85. package/include/opencv2/core/hal/intrin_avx512.hpp +0 -3090
  86. package/include/opencv2/core/hal/intrin_cpp.hpp +0 -3321
  87. package/include/opencv2/core/hal/intrin_forward.hpp +0 -191
  88. package/include/opencv2/core/hal/intrin_lasx.hpp +0 -3236
  89. package/include/opencv2/core/hal/intrin_msa.hpp +0 -1887
  90. package/include/opencv2/core/hal/intrin_neon.hpp +0 -2610
  91. package/include/opencv2/core/hal/intrin_rvv.hpp +0 -3320
  92. package/include/opencv2/core/hal/intrin_rvv071.hpp +0 -2545
  93. package/include/opencv2/core/hal/intrin_rvv_scalable.hpp +0 -2080
  94. package/include/opencv2/core/hal/intrin_sse.hpp +0 -3467
  95. package/include/opencv2/core/hal/intrin_sse_em.hpp +0 -180
  96. package/include/opencv2/core/hal/intrin_vsx.hpp +0 -1608
  97. package/include/opencv2/core/hal/intrin_wasm.hpp +0 -2782
  98. package/include/opencv2/core/hal/msa_macros.h +0 -1558
  99. package/include/opencv2/core/hal/simd_utils.impl.hpp +0 -186
  100. package/include/opencv2/core/llapi/llapi.h +0 -102
  101. package/include/opencv2/core/mat.hpp +0 -3775
  102. package/include/opencv2/core/mat.inl.hpp +0 -3422
  103. package/include/opencv2/core/matx.hpp +0 -1536
  104. package/include/opencv2/core/neon_utils.hpp +0 -128
  105. package/include/opencv2/core/ocl.hpp +0 -917
  106. package/include/opencv2/core/ocl_genbase.hpp +0 -69
  107. package/include/opencv2/core/opencl/ocl_defs.hpp +0 -82
  108. package/include/opencv2/core/opencl/opencl_info.hpp +0 -212
  109. package/include/opencv2/core/opencl/opencl_svm.hpp +0 -81
  110. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clblas.hpp +0 -602
  111. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_clfft.hpp +0 -146
  112. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core.hpp +0 -371
  113. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_core_wrappers.hpp +0 -272
  114. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl.hpp +0 -62
  115. package/include/opencv2/core/opencl/runtime/autogenerated/opencl_gl_wrappers.hpp +0 -42
  116. package/include/opencv2/core/opencl/runtime/opencl_clblas.hpp +0 -53
  117. package/include/opencv2/core/opencl/runtime/opencl_clfft.hpp +0 -53
  118. package/include/opencv2/core/opencl/runtime/opencl_core.hpp +0 -84
  119. package/include/opencv2/core/opencl/runtime/opencl_core_wrappers.hpp +0 -47
  120. package/include/opencv2/core/opencl/runtime/opencl_gl.hpp +0 -53
  121. package/include/opencv2/core/opencl/runtime/opencl_gl_wrappers.hpp +0 -47
  122. package/include/opencv2/core/opencl/runtime/opencl_svm_20.hpp +0 -48
  123. package/include/opencv2/core/opencl/runtime/opencl_svm_definitions.hpp +0 -42
  124. package/include/opencv2/core/opencl/runtime/opencl_svm_hsa_extension.hpp +0 -166
  125. package/include/opencv2/core/opengl.hpp +0 -733
  126. package/include/opencv2/core/openvx/ovx_defs.hpp +0 -48
  127. package/include/opencv2/core/operations.hpp +0 -610
  128. package/include/opencv2/core/optim.hpp +0 -302
  129. package/include/opencv2/core/ovx.hpp +0 -28
  130. package/include/opencv2/core/parallel/backend/parallel_for.openmp.hpp +0 -72
  131. package/include/opencv2/core/parallel/backend/parallel_for.tbb.hpp +0 -153
  132. package/include/opencv2/core/parallel/parallel_backend.hpp +0 -90
  133. package/include/opencv2/core/persistence.hpp +0 -1350
  134. package/include/opencv2/core/private/cv_cpu_include_simd_declarations.hpp +0 -30
  135. package/include/opencv2/core/private.cuda.hpp +0 -169
  136. package/include/opencv2/core/private.hpp +0 -896
  137. package/include/opencv2/core/quaternion.hpp +0 -1696
  138. package/include/opencv2/core/quaternion.inl.hpp +0 -1063
  139. package/include/opencv2/core/saturate.hpp +0 -180
  140. package/include/opencv2/core/simd_intrinsics.hpp +0 -87
  141. package/include/opencv2/core/softfloat.hpp +0 -514
  142. package/include/opencv2/core/sse_utils.hpp +0 -652
  143. package/include/opencv2/core/traits.hpp +0 -417
  144. package/include/opencv2/core/types.hpp +0 -2457
  145. package/include/opencv2/core/types_c.h +0 -2126
  146. package/include/opencv2/core/utility.hpp +0 -1229
  147. package/include/opencv2/core/utils/allocator_stats.hpp +0 -29
  148. package/include/opencv2/core/utils/allocator_stats.impl.hpp +0 -158
  149. package/include/opencv2/core/utils/buffer_area.private.hpp +0 -136
  150. package/include/opencv2/core/utils/configuration.private.hpp +0 -22
  151. package/include/opencv2/core/utils/filesystem.hpp +0 -82
  152. package/include/opencv2/core/utils/filesystem.private.hpp +0 -66
  153. package/include/opencv2/core/utils/fp_control.private.hpp +0 -29
  154. package/include/opencv2/core/utils/fp_control_utils.hpp +0 -69
  155. package/include/opencv2/core/utils/instrumentation.hpp +0 -125
  156. package/include/opencv2/core/utils/lock.private.hpp +0 -119
  157. package/include/opencv2/core/utils/logger.defines.hpp +0 -42
  158. package/include/opencv2/core/utils/logger.hpp +0 -218
  159. package/include/opencv2/core/utils/logtag.hpp +0 -28
  160. package/include/opencv2/core/utils/plugin_loader.private.hpp +0 -165
  161. package/include/opencv2/core/utils/tls.hpp +0 -235
  162. package/include/opencv2/core/utils/trace.hpp +0 -252
  163. package/include/opencv2/core/utils/trace.private.hpp +0 -421
  164. package/include/opencv2/core/va_intel.hpp +0 -75
  165. package/include/opencv2/core/version.hpp +0 -26
  166. package/include/opencv2/core/vsx_utils.hpp +0 -1047
  167. package/include/opencv2/core.hpp +0 -3365
  168. package/include/opencv2/imgcodecs/imgcodecs.hpp +0 -48
  169. package/include/opencv2/imgcodecs/imgcodecs_c.h +0 -1
  170. package/include/opencv2/imgcodecs/ios.h +0 -59
  171. package/include/opencv2/imgcodecs/legacy/constants_c.h +0 -54
  172. package/include/opencv2/imgcodecs/macosx.h +0 -20
  173. package/include/opencv2/imgcodecs.hpp +0 -407
  174. package/include/opencv2/imgproc/bindings.hpp +0 -34
  175. package/include/opencv2/imgproc/detail/gcgraph.hpp +0 -395
  176. package/include/opencv2/imgproc/hal/hal.hpp +0 -246
  177. package/include/opencv2/imgproc/hal/interface.h +0 -46
  178. package/include/opencv2/imgproc/imgproc.hpp +0 -48
  179. package/include/opencv2/imgproc/imgproc_c.h +0 -1177
  180. package/include/opencv2/imgproc/segmentation.hpp +0 -141
  181. package/include/opencv2/imgproc/types_c.h +0 -659
  182. package/include/opencv2/imgproc.hpp +0 -5035
  183. package/include/opencv2/opencv_modules.hpp +0 -17
  184. package/libs/libjpeg-turbo.lib +0 -0
  185. package/libs/libpng.lib +0 -0
  186. package/libs/opencv_core470.lib +0 -0
  187. package/libs/opencv_imgcodecs470.lib +0 -0
  188. package/libs/opencv_imgproc470.lib +0 -0
  189. package/libs/zlib.lib +0 -0
  190. /package/dist/{keyCodes.js → keyCodes.cjs} +0 -0
  191. /package/dist/{keyCodes.d.ts → keyCodes.d.cts} +0 -0
@@ -1,2457 +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
- // Third party copyrights are property of their respective owners.
17
- //
18
- // Redistribution and use in source and binary forms, with or without modification,
19
- // are permitted provided that the following conditions are met:
20
- //
21
- // * Redistribution's of source code must retain the above copyright notice,
22
- // this list of conditions and the following disclaimer.
23
- //
24
- // * Redistribution's in binary form must reproduce the above copyright notice,
25
- // this list of conditions and the following disclaimer in the documentation
26
- // and/or other materials provided with the distribution.
27
- //
28
- // * The name of the copyright holders may not be used to endorse or promote products
29
- // derived from this software without specific prior written permission.
30
- //
31
- // This software is provided by the copyright holders and contributors "as is" and
32
- // any express or implied warranties, including, but not limited to, the implied
33
- // warranties of merchantability and fitness for a particular purpose are disclaimed.
34
- // In no event shall the Intel Corporation or contributors be liable for any direct,
35
- // indirect, incidental, special, exemplary, or consequential damages
36
- // (including, but not limited to, procurement of substitute goods or services;
37
- // loss of use, data, or profits; or business interruption) however caused
38
- // and on any theory of liability, whether in contract, strict liability,
39
- // or tort (including negligence or otherwise) arising in any way out of
40
- // the use of this software, even if advised of the possibility of such damage.
41
- //
42
- //M*/
43
-
44
- #ifndef OPENCV_CORE_TYPES_HPP
45
- #define OPENCV_CORE_TYPES_HPP
46
-
47
- #ifndef __cplusplus
48
- # error types.hpp header must be compiled as C++
49
- #endif
50
-
51
- #include <climits>
52
- #include <cfloat>
53
- #include <vector>
54
- #include <limits>
55
-
56
- #include "opencv2/core/cvdef.h"
57
- #include "opencv2/core/cvstd.hpp"
58
- #include "opencv2/core/matx.hpp"
59
-
60
- #ifdef _MSC_VER
61
- #pragma warning(push)
62
- #pragma warning(disable: 4459) // declaration of '...' hides global declaration
63
- #endif
64
-
65
- namespace cv
66
- {
67
-
68
- //! @addtogroup core_basic
69
- //! @{
70
-
71
- //////////////////////////////// Complex //////////////////////////////
72
-
73
- /** @brief A complex number class.
74
-
75
- The template class is similar and compatible with std::complex, however it provides slightly
76
- more convenient access to the real and imaginary parts using through the simple field access, as opposite
77
- to std::complex::real() and std::complex::imag().
78
- */
79
- template<typename _Tp> class Complex
80
- {
81
- public:
82
-
83
- //! default constructor
84
- Complex();
85
- Complex( _Tp _re, _Tp _im = 0 );
86
-
87
- //! conversion to another data type
88
- template<typename T2> operator Complex<T2>() const;
89
- //! conjugation
90
- Complex conj() const;
91
-
92
- _Tp re, im; //< the real and the imaginary parts
93
- };
94
-
95
- typedef Complex<float> Complexf;
96
- typedef Complex<double> Complexd;
97
-
98
- template<typename _Tp> class DataType< Complex<_Tp> >
99
- {
100
- public:
101
- typedef Complex<_Tp> value_type;
102
- typedef value_type work_type;
103
- typedef _Tp channel_type;
104
-
105
- enum { generic_type = 0,
106
- channels = 2,
107
- fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
108
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
109
- ,depth = DataType<channel_type>::depth
110
- ,type = CV_MAKETYPE(depth, channels)
111
- #endif
112
- };
113
-
114
- typedef Vec<channel_type, channels> vec_type;
115
- };
116
-
117
- namespace traits {
118
- template<typename _Tp>
119
- struct Depth< Complex<_Tp> > { enum { value = Depth<_Tp>::value }; };
120
- template<typename _Tp>
121
- struct Type< Complex<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; };
122
- } // namespace
123
-
124
-
125
- //////////////////////////////// Point_ ////////////////////////////////
126
-
127
- /** @brief Template class for 2D points specified by its coordinates `x` and `y`.
128
-
129
- An instance of the class is interchangeable with C structures, CvPoint and CvPoint2D32f . There is
130
- also a cast operator to convert point coordinates to the specified type. The conversion from
131
- floating-point coordinates to integer coordinates is done by rounding. Commonly, the conversion
132
- uses this operation for each of the coordinates. Besides the class members listed in the
133
- declaration above, the following operations on points are implemented:
134
- @code
135
- pt1 = pt2 + pt3;
136
- pt1 = pt2 - pt3;
137
- pt1 = pt2 * a;
138
- pt1 = a * pt2;
139
- pt1 = pt2 / a;
140
- pt1 += pt2;
141
- pt1 -= pt2;
142
- pt1 *= a;
143
- pt1 /= a;
144
- double value = norm(pt); // L2 norm
145
- pt1 == pt2;
146
- pt1 != pt2;
147
- @endcode
148
- For your convenience, the following type aliases are defined:
149
- @code
150
- typedef Point_<int> Point2i;
151
- typedef Point2i Point;
152
- typedef Point_<float> Point2f;
153
- typedef Point_<double> Point2d;
154
- @endcode
155
- Example:
156
- @code
157
- Point2f a(0.3f, 0.f), b(0.f, 0.4f);
158
- Point pt = (a + b)*10.f;
159
- cout << pt.x << ", " << pt.y << endl;
160
- @endcode
161
- */
162
- template<typename _Tp> class Point_
163
- {
164
- public:
165
- typedef _Tp value_type;
166
-
167
- //! default constructor
168
- Point_();
169
- Point_(_Tp _x, _Tp _y);
170
- #if (defined(__GNUC__) && __GNUC__ < 5) && !defined(__clang__) // GCC 4.x bug. Details: https://github.com/opencv/opencv/pull/20837
171
- Point_(const Point_& pt);
172
- Point_(Point_&& pt) CV_NOEXCEPT = default;
173
- #elif OPENCV_ABI_COMPATIBILITY < 500
174
- Point_(const Point_& pt) = default;
175
- Point_(Point_&& pt) CV_NOEXCEPT = default;
176
- #endif
177
- Point_(const Size_<_Tp>& sz);
178
- Point_(const Vec<_Tp, 2>& v);
179
-
180
- #if (defined(__GNUC__) && __GNUC__ < 5) && !defined(__clang__) // GCC 4.x bug. Details: https://github.com/opencv/opencv/pull/20837
181
- Point_& operator = (const Point_& pt);
182
- Point_& operator = (Point_&& pt) CV_NOEXCEPT = default;
183
- #elif OPENCV_ABI_COMPATIBILITY < 500
184
- Point_& operator = (const Point_& pt) = default;
185
- Point_& operator = (Point_&& pt) CV_NOEXCEPT = default;
186
- #endif
187
- //! conversion to another data type
188
- template<typename _Tp2> operator Point_<_Tp2>() const;
189
-
190
- //! conversion to the old-style C structures
191
- operator Vec<_Tp, 2>() const;
192
-
193
- //! dot product
194
- _Tp dot(const Point_& pt) const;
195
- //! dot product computed in double-precision arithmetics
196
- double ddot(const Point_& pt) const;
197
- //! cross-product
198
- double cross(const Point_& pt) const;
199
- //! checks whether the point is inside the specified rectangle
200
- bool inside(const Rect_<_Tp>& r) const;
201
- _Tp x; //!< x coordinate of the point
202
- _Tp y; //!< y coordinate of the point
203
- };
204
-
205
- typedef Point_<int> Point2i;
206
- typedef Point_<int64> Point2l;
207
- typedef Point_<float> Point2f;
208
- typedef Point_<double> Point2d;
209
- typedef Point2i Point;
210
-
211
- template<typename _Tp> class DataType< Point_<_Tp> >
212
- {
213
- public:
214
- typedef Point_<_Tp> value_type;
215
- typedef Point_<typename DataType<_Tp>::work_type> work_type;
216
- typedef _Tp channel_type;
217
-
218
- enum { generic_type = 0,
219
- channels = 2,
220
- fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
221
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
222
- ,depth = DataType<channel_type>::depth
223
- ,type = CV_MAKETYPE(depth, channels)
224
- #endif
225
- };
226
-
227
- typedef Vec<channel_type, channels> vec_type;
228
- };
229
-
230
- namespace traits {
231
- template<typename _Tp>
232
- struct Depth< Point_<_Tp> > { enum { value = Depth<_Tp>::value }; };
233
- template<typename _Tp>
234
- struct Type< Point_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; };
235
- } // namespace
236
-
237
-
238
- //////////////////////////////// Point3_ ////////////////////////////////
239
-
240
- /** @brief Template class for 3D points specified by its coordinates `x`, `y` and `z`.
241
-
242
- An instance of the class is interchangeable with the C structure CvPoint2D32f . Similarly to
243
- Point_ , the coordinates of 3D points can be converted to another type. The vector arithmetic and
244
- comparison operations are also supported.
245
-
246
- The following Point3_\<\> aliases are available:
247
- @code
248
- typedef Point3_<int> Point3i;
249
- typedef Point3_<float> Point3f;
250
- typedef Point3_<double> Point3d;
251
- @endcode
252
- @see cv::Point3i, cv::Point3f and cv::Point3d
253
- */
254
- template<typename _Tp> class Point3_
255
- {
256
- public:
257
- typedef _Tp value_type;
258
-
259
- //! default constructor
260
- Point3_();
261
- Point3_(_Tp _x, _Tp _y, _Tp _z);
262
- #if OPENCV_ABI_COMPATIBILITY < 500
263
- Point3_(const Point3_& pt) = default;
264
- Point3_(Point3_&& pt) CV_NOEXCEPT = default;
265
- #endif
266
- explicit Point3_(const Point_<_Tp>& pt);
267
- Point3_(const Vec<_Tp, 3>& v);
268
-
269
- #if OPENCV_ABI_COMPATIBILITY < 500
270
- Point3_& operator = (const Point3_& pt) = default;
271
- Point3_& operator = (Point3_&& pt) CV_NOEXCEPT = default;
272
- #endif
273
- //! conversion to another data type
274
- template<typename _Tp2> operator Point3_<_Tp2>() const;
275
- //! conversion to cv::Vec<>
276
- operator Vec<_Tp, 3>() const;
277
-
278
- //! dot product
279
- _Tp dot(const Point3_& pt) const;
280
- //! dot product computed in double-precision arithmetics
281
- double ddot(const Point3_& pt) const;
282
- //! cross product of the 2 3D points
283
- Point3_ cross(const Point3_& pt) const;
284
- _Tp x; //!< x coordinate of the 3D point
285
- _Tp y; //!< y coordinate of the 3D point
286
- _Tp z; //!< z coordinate of the 3D point
287
- };
288
-
289
- typedef Point3_<int> Point3i;
290
- typedef Point3_<float> Point3f;
291
- typedef Point3_<double> Point3d;
292
-
293
- template<typename _Tp> class DataType< Point3_<_Tp> >
294
- {
295
- public:
296
- typedef Point3_<_Tp> value_type;
297
- typedef Point3_<typename DataType<_Tp>::work_type> work_type;
298
- typedef _Tp channel_type;
299
-
300
- enum { generic_type = 0,
301
- channels = 3,
302
- fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
303
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
304
- ,depth = DataType<channel_type>::depth
305
- ,type = CV_MAKETYPE(depth, channels)
306
- #endif
307
- };
308
-
309
- typedef Vec<channel_type, channels> vec_type;
310
- };
311
-
312
- namespace traits {
313
- template<typename _Tp>
314
- struct Depth< Point3_<_Tp> > { enum { value = Depth<_Tp>::value }; };
315
- template<typename _Tp>
316
- struct Type< Point3_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 3) }; };
317
- } // namespace
318
-
319
- //////////////////////////////// Size_ ////////////////////////////////
320
-
321
- /** @brief Template class for specifying the size of an image or rectangle.
322
-
323
- The class includes two members called width and height. The structure can be converted to and from
324
- the old OpenCV structures CvSize and CvSize2D32f . The same set of arithmetic and comparison
325
- operations as for Point_ is available.
326
-
327
- OpenCV defines the following Size_\<\> aliases:
328
- @code
329
- typedef Size_<int> Size2i;
330
- typedef Size2i Size;
331
- typedef Size_<float> Size2f;
332
- @endcode
333
- */
334
- template<typename _Tp> class Size_
335
- {
336
- public:
337
- typedef _Tp value_type;
338
-
339
- //! default constructor
340
- Size_();
341
- Size_(_Tp _width, _Tp _height);
342
- #if OPENCV_ABI_COMPATIBILITY < 500
343
- Size_(const Size_& sz) = default;
344
- Size_(Size_&& sz) CV_NOEXCEPT = default;
345
- #endif
346
- Size_(const Point_<_Tp>& pt);
347
-
348
- #if OPENCV_ABI_COMPATIBILITY < 500
349
- Size_& operator = (const Size_& sz) = default;
350
- Size_& operator = (Size_&& sz) CV_NOEXCEPT = default;
351
- #endif
352
- //! the area (width*height)
353
- _Tp area() const;
354
- //! aspect ratio (width/height)
355
- double aspectRatio() const;
356
- //! true if empty
357
- bool empty() const;
358
-
359
- //! conversion of another data type.
360
- template<typename _Tp2> operator Size_<_Tp2>() const;
361
-
362
- _Tp width; //!< the width
363
- _Tp height; //!< the height
364
- };
365
-
366
- typedef Size_<int> Size2i;
367
- typedef Size_<int64> Size2l;
368
- typedef Size_<float> Size2f;
369
- typedef Size_<double> Size2d;
370
- typedef Size2i Size;
371
-
372
- template<typename _Tp> class DataType< Size_<_Tp> >
373
- {
374
- public:
375
- typedef Size_<_Tp> value_type;
376
- typedef Size_<typename DataType<_Tp>::work_type> work_type;
377
- typedef _Tp channel_type;
378
-
379
- enum { generic_type = 0,
380
- channels = 2,
381
- fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
382
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
383
- ,depth = DataType<channel_type>::depth
384
- ,type = CV_MAKETYPE(depth, channels)
385
- #endif
386
- };
387
-
388
- typedef Vec<channel_type, channels> vec_type;
389
- };
390
-
391
- namespace traits {
392
- template<typename _Tp>
393
- struct Depth< Size_<_Tp> > { enum { value = Depth<_Tp>::value }; };
394
- template<typename _Tp>
395
- struct Type< Size_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 2) }; };
396
- } // namespace
397
-
398
- //////////////////////////////// Rect_ ////////////////////////////////
399
-
400
- /** @brief Template class for 2D rectangles
401
-
402
- described by the following parameters:
403
- - Coordinates of the top-left corner. This is a default interpretation of Rect_::x and Rect_::y
404
- in OpenCV. Though, in your algorithms you may count x and y from the bottom-left corner.
405
- - Rectangle width and height.
406
-
407
- OpenCV typically assumes that the top and left boundary of the rectangle are inclusive, while the
408
- right and bottom boundaries are not. For example, the method Rect_::contains returns true if
409
-
410
- \f[x \leq pt.x < x+width,
411
- y \leq pt.y < y+height\f]
412
-
413
- Virtually every loop over an image ROI in OpenCV (where ROI is specified by Rect_\<int\> ) is
414
- implemented as:
415
- @code
416
- for(int y = roi.y; y < roi.y + roi.height; y++)
417
- for(int x = roi.x; x < roi.x + roi.width; x++)
418
- {
419
- // ...
420
- }
421
- @endcode
422
- In addition to the class members, the following operations on rectangles are implemented:
423
- - \f$\texttt{rect} = \texttt{rect} \pm \texttt{point}\f$ (shifting a rectangle by a certain offset)
424
- - \f$\texttt{rect} = \texttt{rect} \pm \texttt{size}\f$ (expanding or shrinking a rectangle by a
425
- certain amount)
426
- - rect += point, rect -= point, rect += size, rect -= size (augmenting operations)
427
- - rect = rect1 & rect2 (rectangle intersection)
428
- - rect = rect1 | rect2 (minimum area rectangle containing rect1 and rect2 )
429
- - rect &= rect1, rect |= rect1 (and the corresponding augmenting operations)
430
- - rect == rect1, rect != rect1 (rectangle comparison)
431
-
432
- This is an example how the partial ordering on rectangles can be established (rect1 \f$\subseteq\f$
433
- rect2):
434
- @code
435
- template<typename _Tp> inline bool
436
- operator <= (const Rect_<_Tp>& r1, const Rect_<_Tp>& r2)
437
- {
438
- return (r1 & r2) == r1;
439
- }
440
- @endcode
441
- For your convenience, the Rect_\<\> alias is available: cv::Rect
442
- */
443
- template<typename _Tp> class Rect_
444
- {
445
- public:
446
- typedef _Tp value_type;
447
-
448
- //! default constructor
449
- Rect_();
450
- Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height);
451
- #if OPENCV_ABI_COMPATIBILITY < 500
452
- Rect_(const Rect_& r) = default;
453
- Rect_(Rect_&& r) CV_NOEXCEPT = default;
454
- #endif
455
- Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz);
456
- Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2);
457
-
458
- #if OPENCV_ABI_COMPATIBILITY < 500
459
- Rect_& operator = (const Rect_& r) = default;
460
- Rect_& operator = (Rect_&& r) CV_NOEXCEPT = default;
461
- #endif
462
- //! the top-left corner
463
- Point_<_Tp> tl() const;
464
- //! the bottom-right corner
465
- Point_<_Tp> br() const;
466
-
467
- //! size (width, height) of the rectangle
468
- Size_<_Tp> size() const;
469
- //! area (width*height) of the rectangle
470
- _Tp area() const;
471
- //! true if empty
472
- bool empty() const;
473
-
474
- //! conversion to another data type
475
- template<typename _Tp2> operator Rect_<_Tp2>() const;
476
-
477
- //! checks whether the rectangle contains the point
478
- bool contains(const Point_<_Tp>& pt) const;
479
-
480
- _Tp x; //!< x coordinate of the top-left corner
481
- _Tp y; //!< y coordinate of the top-left corner
482
- _Tp width; //!< width of the rectangle
483
- _Tp height; //!< height of the rectangle
484
- };
485
-
486
- typedef Rect_<int> Rect2i;
487
- typedef Rect_<float> Rect2f;
488
- typedef Rect_<double> Rect2d;
489
- typedef Rect2i Rect;
490
-
491
- template<typename _Tp> class DataType< Rect_<_Tp> >
492
- {
493
- public:
494
- typedef Rect_<_Tp> value_type;
495
- typedef Rect_<typename DataType<_Tp>::work_type> work_type;
496
- typedef _Tp channel_type;
497
-
498
- enum { generic_type = 0,
499
- channels = 4,
500
- fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
501
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
502
- ,depth = DataType<channel_type>::depth
503
- ,type = CV_MAKETYPE(depth, channels)
504
- #endif
505
- };
506
-
507
- typedef Vec<channel_type, channels> vec_type;
508
- };
509
-
510
- namespace traits {
511
- template<typename _Tp>
512
- struct Depth< Rect_<_Tp> > { enum { value = Depth<_Tp>::value }; };
513
- template<typename _Tp>
514
- struct Type< Rect_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; };
515
- } // namespace
516
-
517
- ///////////////////////////// RotatedRect /////////////////////////////
518
-
519
- /** @brief The class represents rotated (i.e. not up-right) rectangles on a plane.
520
-
521
- Each rectangle is specified by the center point (mass center), length of each side (represented by
522
- #Size2f structure) and the rotation angle in degrees.
523
-
524
- The sample below demonstrates how to use RotatedRect:
525
- @snippet snippets/core_various.cpp RotatedRect_demo
526
- ![image](pics/rotatedrect.png)
527
-
528
- @sa CamShift, fitEllipse, minAreaRect, CvBox2D
529
- */
530
- class CV_EXPORTS RotatedRect
531
- {
532
- public:
533
- //! default constructor
534
- RotatedRect();
535
- /** full constructor
536
- @param center The rectangle mass center.
537
- @param size Width and height of the rectangle.
538
- @param angle The rotation angle in a clockwise direction. When the angle is 0, 90, 180, 270 etc.,
539
- the rectangle becomes an up-right rectangle.
540
- */
541
- RotatedRect(const Point2f& center, const Size2f& size, float angle);
542
- /**
543
- Any 3 end points of the RotatedRect. They must be given in order (either clockwise or
544
- anticlockwise).
545
- */
546
- RotatedRect(const Point2f& point1, const Point2f& point2, const Point2f& point3);
547
-
548
- /** returns 4 vertices of the rectangle
549
- @param pts The points array for storing rectangle vertices. The order is bottomLeft, topLeft, topRight, bottomRight.
550
- */
551
- void points(Point2f pts[]) const;
552
- //! returns the minimal up-right integer rectangle containing the rotated rectangle
553
- Rect boundingRect() const;
554
- //! returns the minimal (exact) floating point rectangle containing the rotated rectangle, not intended for use with images
555
- Rect_<float> boundingRect2f() const;
556
- //! returns the rectangle mass center
557
- Point2f center;
558
- //! returns width and height of the rectangle
559
- Size2f size;
560
- //! returns the rotation angle. When the angle is 0, 90, 180, 270 etc., the rectangle becomes an up-right rectangle.
561
- float angle;
562
- };
563
-
564
- template<> class DataType< RotatedRect >
565
- {
566
- public:
567
- typedef RotatedRect value_type;
568
- typedef value_type work_type;
569
- typedef float channel_type;
570
-
571
- enum { generic_type = 0,
572
- channels = (int)sizeof(value_type)/sizeof(channel_type), // 5
573
- fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
574
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
575
- ,depth = DataType<channel_type>::depth
576
- ,type = CV_MAKETYPE(depth, channels)
577
- #endif
578
- };
579
-
580
- typedef Vec<channel_type, channels> vec_type;
581
- };
582
-
583
- namespace traits {
584
- template<>
585
- struct Depth< RotatedRect > { enum { value = Depth<float>::value }; };
586
- template<>
587
- struct Type< RotatedRect > { enum { value = CV_MAKETYPE(Depth<float>::value, (int)sizeof(RotatedRect)/sizeof(float)) }; };
588
- } // namespace
589
-
590
-
591
- //////////////////////////////// Range /////////////////////////////////
592
-
593
- /** @brief Template class specifying a continuous subsequence (slice) of a sequence.
594
-
595
- The class is used to specify a row or a column span in a matrix ( Mat ) and for many other purposes.
596
- Range(a,b) is basically the same as a:b in Matlab or a..b in Python. As in Python, start is an
597
- inclusive left boundary of the range and end is an exclusive right boundary of the range. Such a
598
- half-opened interval is usually denoted as \f$[start,end)\f$ .
599
-
600
- The static method Range::all() returns a special variable that means "the whole sequence" or "the
601
- whole range", just like " : " in Matlab or " ... " in Python. All the methods and functions in
602
- OpenCV that take Range support this special Range::all() value. But, of course, in case of your own
603
- custom processing, you will probably have to check and handle it explicitly:
604
- @code
605
- void my_function(..., const Range& r, ....)
606
- {
607
- if(r == Range::all()) {
608
- // process all the data
609
- }
610
- else {
611
- // process [r.start, r.end)
612
- }
613
- }
614
- @endcode
615
- */
616
- class CV_EXPORTS Range
617
- {
618
- public:
619
- Range();
620
- Range(int _start, int _end);
621
- int size() const;
622
- bool empty() const;
623
- static Range all();
624
-
625
- int start, end;
626
- };
627
-
628
- template<> class DataType<Range>
629
- {
630
- public:
631
- typedef Range value_type;
632
- typedef value_type work_type;
633
- typedef int channel_type;
634
-
635
- enum { generic_type = 0,
636
- channels = 2,
637
- fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
638
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
639
- ,depth = DataType<channel_type>::depth
640
- ,type = CV_MAKETYPE(depth, channels)
641
- #endif
642
- };
643
-
644
- typedef Vec<channel_type, channels> vec_type;
645
- };
646
-
647
- namespace traits {
648
- template<>
649
- struct Depth< Range > { enum { value = Depth<int>::value }; };
650
- template<>
651
- struct Type< Range > { enum { value = CV_MAKETYPE(Depth<int>::value, 2) }; };
652
- } // namespace
653
-
654
-
655
- //////////////////////////////// Scalar_ ///////////////////////////////
656
-
657
- /** @brief Template class for a 4-element vector derived from Vec.
658
-
659
- Being derived from Vec\<_Tp, 4\> , Scalar\_ and Scalar can be used just as typical 4-element
660
- vectors. In addition, they can be converted to/from CvScalar . The type Scalar is widely used in
661
- OpenCV to pass pixel values.
662
- */
663
- template<typename _Tp> class Scalar_ : public Vec<_Tp, 4>
664
- {
665
- public:
666
- //! default constructor
667
- Scalar_();
668
- Scalar_(_Tp v0, _Tp v1, _Tp v2=0, _Tp v3=0);
669
- Scalar_(_Tp v0);
670
-
671
- Scalar_(const Scalar_& s);
672
- Scalar_(Scalar_&& s) CV_NOEXCEPT;
673
-
674
- Scalar_& operator=(const Scalar_& s);
675
- Scalar_& operator=(Scalar_&& s) CV_NOEXCEPT;
676
-
677
- template<typename _Tp2, int cn>
678
- Scalar_(const Vec<_Tp2, cn>& v);
679
-
680
- //! returns a scalar with all elements set to v0
681
- static Scalar_<_Tp> all(_Tp v0);
682
-
683
- //! conversion to another data type
684
- template<typename T2> operator Scalar_<T2>() const;
685
-
686
- //! per-element product
687
- Scalar_<_Tp> mul(const Scalar_<_Tp>& a, double scale=1 ) const;
688
-
689
- //! returns (v0, -v1, -v2, -v3)
690
- Scalar_<_Tp> conj() const;
691
-
692
- //! returns true iff v1 == v2 == v3 == 0
693
- bool isReal() const;
694
- };
695
-
696
- typedef Scalar_<double> Scalar;
697
-
698
- template<typename _Tp> class DataType< Scalar_<_Tp> >
699
- {
700
- public:
701
- typedef Scalar_<_Tp> value_type;
702
- typedef Scalar_<typename DataType<_Tp>::work_type> work_type;
703
- typedef _Tp channel_type;
704
-
705
- enum { generic_type = 0,
706
- channels = 4,
707
- fmt = traits::SafeFmt<channel_type>::fmt + ((channels - 1) << 8)
708
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
709
- ,depth = DataType<channel_type>::depth
710
- ,type = CV_MAKETYPE(depth, channels)
711
- #endif
712
- };
713
-
714
- typedef Vec<channel_type, channels> vec_type;
715
- };
716
-
717
- namespace traits {
718
- template<typename _Tp>
719
- struct Depth< Scalar_<_Tp> > { enum { value = Depth<_Tp>::value }; };
720
- template<typename _Tp>
721
- struct Type< Scalar_<_Tp> > { enum { value = CV_MAKETYPE(Depth<_Tp>::value, 4) }; };
722
- } // namespace
723
-
724
-
725
- /////////////////////////////// KeyPoint ////////////////////////////////
726
-
727
- /** @brief Data structure for salient point detectors.
728
-
729
- The class instance stores a keypoint, i.e. a point feature found by one of many available keypoint
730
- detectors, such as Harris corner detector, #FAST, %StarDetector, %SURF, %SIFT etc.
731
-
732
- The keypoint is characterized by the 2D position, scale (proportional to the diameter of the
733
- neighborhood that needs to be taken into account), orientation and some other parameters. The
734
- keypoint neighborhood is then analyzed by another algorithm that builds a descriptor (usually
735
- represented as a feature vector). The keypoints representing the same object in different images
736
- can then be matched using %KDTree or another method.
737
- */
738
- class CV_EXPORTS_W_SIMPLE KeyPoint
739
- {
740
- public:
741
- //! the default constructor
742
- CV_WRAP KeyPoint();
743
- /**
744
- @param pt x & y coordinates of the keypoint
745
- @param size keypoint diameter
746
- @param angle keypoint orientation
747
- @param response keypoint detector response on the keypoint (that is, strength of the keypoint)
748
- @param octave pyramid octave in which the keypoint has been detected
749
- @param class_id object id
750
- */
751
- KeyPoint(Point2f pt, float size, float angle=-1, float response=0, int octave=0, int class_id=-1);
752
- /**
753
- @param x x-coordinate of the keypoint
754
- @param y y-coordinate of the keypoint
755
- @param size keypoint diameter
756
- @param angle keypoint orientation
757
- @param response keypoint detector response on the keypoint (that is, strength of the keypoint)
758
- @param octave pyramid octave in which the keypoint has been detected
759
- @param class_id object id
760
- */
761
- CV_WRAP KeyPoint(float x, float y, float size, float angle=-1, float response=0, int octave=0, int class_id=-1);
762
-
763
- size_t hash() const;
764
-
765
- /**
766
- This method converts vector of keypoints to vector of points or the reverse, where each keypoint is
767
- assigned the same size and the same orientation.
768
-
769
- @param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB
770
- @param points2f Array of (x,y) coordinates of each keypoint
771
- @param keypointIndexes Array of indexes of keypoints to be converted to points. (Acts like a mask to
772
- convert only specified keypoints)
773
- */
774
- CV_WRAP static void convert(const std::vector<KeyPoint>& keypoints,
775
- CV_OUT std::vector<Point2f>& points2f,
776
- const std::vector<int>& keypointIndexes=std::vector<int>());
777
- /** @overload
778
- @param points2f Array of (x,y) coordinates of each keypoint
779
- @param keypoints Keypoints obtained from any feature detection algorithm like SIFT/SURF/ORB
780
- @param size keypoint diameter
781
- @param response keypoint detector response on the keypoint (that is, strength of the keypoint)
782
- @param octave pyramid octave in which the keypoint has been detected
783
- @param class_id object id
784
- */
785
- CV_WRAP static void convert(const std::vector<Point2f>& points2f,
786
- CV_OUT std::vector<KeyPoint>& keypoints,
787
- float size=1, float response=1, int octave=0, int class_id=-1);
788
-
789
- /**
790
- This method computes overlap for pair of keypoints. Overlap is the ratio between area of keypoint
791
- regions' intersection and area of keypoint regions' union (considering keypoint region as circle).
792
- If they don't overlap, we get zero. If they coincide at same location with same size, we get 1.
793
- @param kp1 First keypoint
794
- @param kp2 Second keypoint
795
- */
796
- CV_WRAP static float overlap(const KeyPoint& kp1, const KeyPoint& kp2);
797
-
798
- CV_PROP_RW Point2f pt; //!< coordinates of the keypoints
799
- CV_PROP_RW float size; //!< diameter of the meaningful keypoint neighborhood
800
- CV_PROP_RW float angle; //!< computed orientation of the keypoint (-1 if not applicable);
801
- //!< it's in [0,360) degrees and measured relative to
802
- //!< image coordinate system, ie in clockwise.
803
- CV_PROP_RW float response; //!< the response by which the most strong keypoints have been selected. Can be used for the further sorting or subsampling
804
- CV_PROP_RW int octave; //!< octave (pyramid layer) from which the keypoint has been extracted
805
- CV_PROP_RW int class_id; //!< object class (if the keypoints need to be clustered by an object they belong to)
806
- };
807
-
808
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
809
- template<> class DataType<KeyPoint>
810
- {
811
- public:
812
- typedef KeyPoint value_type;
813
- typedef float work_type;
814
- typedef float channel_type;
815
-
816
- enum { generic_type = 0,
817
- depth = DataType<channel_type>::depth,
818
- channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 7
819
- fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
820
- type = CV_MAKETYPE(depth, channels)
821
- };
822
-
823
- typedef Vec<channel_type, channels> vec_type;
824
- };
825
- #endif
826
-
827
-
828
- //////////////////////////////// DMatch /////////////////////////////////
829
-
830
- /** @brief Class for matching keypoint descriptors
831
-
832
- query descriptor index, train descriptor index, train image index, and distance between
833
- descriptors.
834
- */
835
- class CV_EXPORTS_W_SIMPLE DMatch
836
- {
837
- public:
838
- CV_WRAP DMatch();
839
- CV_WRAP DMatch(int _queryIdx, int _trainIdx, float _distance);
840
- CV_WRAP DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance);
841
-
842
- CV_PROP_RW int queryIdx; //!< query descriptor index
843
- CV_PROP_RW int trainIdx; //!< train descriptor index
844
- CV_PROP_RW int imgIdx; //!< train image index
845
-
846
- CV_PROP_RW float distance;
847
-
848
- // less is better
849
- bool operator<(const DMatch &m) const;
850
- };
851
-
852
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
853
- template<> class DataType<DMatch>
854
- {
855
- public:
856
- typedef DMatch value_type;
857
- typedef int work_type;
858
- typedef int channel_type;
859
-
860
- enum { generic_type = 0,
861
- depth = DataType<channel_type>::depth,
862
- channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 4
863
- fmt = DataType<channel_type>::fmt + ((channels - 1) << 8),
864
- type = CV_MAKETYPE(depth, channels)
865
- };
866
-
867
- typedef Vec<channel_type, channels> vec_type;
868
- };
869
- #endif
870
-
871
-
872
- ///////////////////////////// TermCriteria //////////////////////////////
873
-
874
- /** @brief The class defining termination criteria for iterative algorithms.
875
-
876
- You can initialize it by default constructor and then override any parameters, or the structure may
877
- be fully initialized using the advanced variant of the constructor.
878
- */
879
- class CV_EXPORTS TermCriteria
880
- {
881
- public:
882
- /**
883
- Criteria type, can be one of: COUNT, EPS or COUNT + EPS
884
- */
885
- enum Type
886
- {
887
- COUNT=1, //!< the maximum number of iterations or elements to compute
888
- MAX_ITER=COUNT, //!< ditto
889
- EPS=2 //!< the desired accuracy or change in parameters at which the iterative algorithm stops
890
- };
891
-
892
- //! default constructor
893
- TermCriteria();
894
- /**
895
- @param type The type of termination criteria, one of TermCriteria::Type
896
- @param maxCount The maximum number of iterations or elements to compute.
897
- @param epsilon The desired accuracy or change in parameters at which the iterative algorithm stops.
898
- */
899
- TermCriteria(int type, int maxCount, double epsilon);
900
-
901
- inline bool isValid() const
902
- {
903
- const bool isCount = (type & COUNT) && maxCount > 0;
904
- const bool isEps = (type & EPS) && !cvIsNaN(epsilon);
905
- return isCount || isEps;
906
- }
907
-
908
- int type; //!< the type of termination criteria: COUNT, EPS or COUNT + EPS
909
- int maxCount; //!< the maximum number of iterations/elements
910
- double epsilon; //!< the desired accuracy
911
- };
912
-
913
-
914
- //! @} core_basic
915
-
916
- ///////////////////////// raster image moments //////////////////////////
917
-
918
- //! @addtogroup imgproc_shape
919
- //! @{
920
-
921
- /** @brief struct returned by cv::moments
922
-
923
- The spatial moments \f$\texttt{Moments::m}_{ji}\f$ are computed as:
924
-
925
- \f[\texttt{m} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot x^j \cdot y^i \right )\f]
926
-
927
- The central moments \f$\texttt{Moments::mu}_{ji}\f$ are computed as:
928
-
929
- \f[\texttt{mu} _{ji}= \sum _{x,y} \left ( \texttt{array} (x,y) \cdot (x - \bar{x} )^j \cdot (y - \bar{y} )^i \right )\f]
930
-
931
- where \f$(\bar{x}, \bar{y})\f$ is the mass center:
932
-
933
- \f[\bar{x} = \frac{\texttt{m}_{10}}{\texttt{m}_{00}} , \; \bar{y} = \frac{\texttt{m}_{01}}{\texttt{m}_{00}}\f]
934
-
935
- The normalized central moments \f$\texttt{Moments::nu}_{ij}\f$ are computed as:
936
-
937
- \f[\texttt{nu} _{ji}= \frac{\texttt{mu}_{ji}}{\texttt{m}_{00}^{(i+j)/2+1}} .\f]
938
-
939
- @note
940
- \f$\texttt{mu}_{00}=\texttt{m}_{00}\f$, \f$\texttt{nu}_{00}=1\f$
941
- \f$\texttt{nu}_{10}=\texttt{mu}_{10}=\texttt{mu}_{01}=\texttt{mu}_{10}=0\f$ , hence the values are not
942
- stored.
943
-
944
- The moments of a contour are defined in the same way but computed using the Green's formula (see
945
- <http://en.wikipedia.org/wiki/Green_theorem>). So, due to a limited raster resolution, the moments
946
- computed for a contour are slightly different from the moments computed for the same rasterized
947
- contour.
948
-
949
- @note
950
- Since the contour moments are computed using Green formula, you may get seemingly odd results for
951
- contours with self-intersections, e.g. a zero area (m00) for butterfly-shaped contours.
952
- */
953
- class CV_EXPORTS_W_MAP Moments
954
- {
955
- public:
956
- //! the default constructor
957
- Moments();
958
- //! the full constructor
959
- Moments(double m00, double m10, double m01, double m20, double m11,
960
- double m02, double m30, double m21, double m12, double m03 );
961
- ////! the conversion from CvMoments
962
- //Moments( const CvMoments& moments );
963
- ////! the conversion to CvMoments
964
- //operator CvMoments() const;
965
-
966
- //! @name spatial moments
967
- //! @{
968
- CV_PROP_RW double m00, m10, m01, m20, m11, m02, m30, m21, m12, m03;
969
- //! @}
970
-
971
- //! @name central moments
972
- //! @{
973
- CV_PROP_RW double mu20, mu11, mu02, mu30, mu21, mu12, mu03;
974
- //! @}
975
-
976
- //! @name central normalized moments
977
- //! @{
978
- CV_PROP_RW double nu20, nu11, nu02, nu30, nu21, nu12, nu03;
979
- //! @}
980
- };
981
-
982
- template<> class DataType<Moments>
983
- {
984
- public:
985
- typedef Moments value_type;
986
- typedef double work_type;
987
- typedef double channel_type;
988
-
989
- enum { generic_type = 0,
990
- channels = (int)(sizeof(value_type)/sizeof(channel_type)), // 24
991
- fmt = DataType<channel_type>::fmt + ((channels - 1) << 8)
992
- #ifdef OPENCV_TRAITS_ENABLE_DEPRECATED
993
- ,depth = DataType<channel_type>::depth
994
- ,type = CV_MAKETYPE(depth, channels)
995
- #endif
996
- };
997
-
998
- typedef Vec<channel_type, channels> vec_type;
999
- };
1000
-
1001
- namespace traits {
1002
- template<>
1003
- struct Depth< Moments > { enum { value = Depth<double>::value }; };
1004
- template<>
1005
- struct Type< Moments > { enum { value = CV_MAKETYPE(Depth<double>::value, (int)(sizeof(Moments)/sizeof(double))) }; };
1006
- } // namespace
1007
-
1008
- //! @} imgproc_shape
1009
-
1010
- //! @cond IGNORED
1011
-
1012
- /////////////////////////////////////////////////////////////////////////
1013
- ///////////////////////////// Implementation ////////////////////////////
1014
- /////////////////////////////////////////////////////////////////////////
1015
-
1016
- //////////////////////////////// Complex ////////////////////////////////
1017
-
1018
- template<typename _Tp> inline
1019
- Complex<_Tp>::Complex()
1020
- : re(0), im(0) {}
1021
-
1022
- template<typename _Tp> inline
1023
- Complex<_Tp>::Complex( _Tp _re, _Tp _im )
1024
- : re(_re), im(_im) {}
1025
-
1026
- template<typename _Tp> template<typename T2> inline
1027
- Complex<_Tp>::operator Complex<T2>() const
1028
- {
1029
- return Complex<T2>(saturate_cast<T2>(re), saturate_cast<T2>(im));
1030
- }
1031
-
1032
- template<typename _Tp> inline
1033
- Complex<_Tp> Complex<_Tp>::conj() const
1034
- {
1035
- return Complex<_Tp>(re, -im);
1036
- }
1037
-
1038
-
1039
- template<typename _Tp> static inline
1040
- bool operator == (const Complex<_Tp>& a, const Complex<_Tp>& b)
1041
- {
1042
- return a.re == b.re && a.im == b.im;
1043
- }
1044
-
1045
- template<typename _Tp> static inline
1046
- bool operator != (const Complex<_Tp>& a, const Complex<_Tp>& b)
1047
- {
1048
- return a.re != b.re || a.im != b.im;
1049
- }
1050
-
1051
- template<typename _Tp> static inline
1052
- Complex<_Tp> operator + (const Complex<_Tp>& a, const Complex<_Tp>& b)
1053
- {
1054
- return Complex<_Tp>( a.re + b.re, a.im + b.im );
1055
- }
1056
-
1057
- template<typename _Tp> static inline
1058
- Complex<_Tp>& operator += (Complex<_Tp>& a, const Complex<_Tp>& b)
1059
- {
1060
- a.re += b.re; a.im += b.im;
1061
- return a;
1062
- }
1063
-
1064
- template<typename _Tp> static inline
1065
- Complex<_Tp> operator - (const Complex<_Tp>& a, const Complex<_Tp>& b)
1066
- {
1067
- return Complex<_Tp>( a.re - b.re, a.im - b.im );
1068
- }
1069
-
1070
- template<typename _Tp> static inline
1071
- Complex<_Tp>& operator -= (Complex<_Tp>& a, const Complex<_Tp>& b)
1072
- {
1073
- a.re -= b.re; a.im -= b.im;
1074
- return a;
1075
- }
1076
-
1077
- template<typename _Tp> static inline
1078
- Complex<_Tp> operator - (const Complex<_Tp>& a)
1079
- {
1080
- return Complex<_Tp>(-a.re, -a.im);
1081
- }
1082
-
1083
- template<typename _Tp> static inline
1084
- Complex<_Tp> operator * (const Complex<_Tp>& a, const Complex<_Tp>& b)
1085
- {
1086
- return Complex<_Tp>( a.re*b.re - a.im*b.im, a.re*b.im + a.im*b.re );
1087
- }
1088
-
1089
- template<typename _Tp> static inline
1090
- Complex<_Tp> operator * (const Complex<_Tp>& a, _Tp b)
1091
- {
1092
- return Complex<_Tp>( a.re*b, a.im*b );
1093
- }
1094
-
1095
- template<typename _Tp> static inline
1096
- Complex<_Tp> operator * (_Tp b, const Complex<_Tp>& a)
1097
- {
1098
- return Complex<_Tp>( a.re*b, a.im*b );
1099
- }
1100
-
1101
- template<typename _Tp> static inline
1102
- Complex<_Tp> operator + (const Complex<_Tp>& a, _Tp b)
1103
- {
1104
- return Complex<_Tp>( a.re + b, a.im );
1105
- }
1106
-
1107
- template<typename _Tp> static inline
1108
- Complex<_Tp> operator - (const Complex<_Tp>& a, _Tp b)
1109
- { return Complex<_Tp>( a.re - b, a.im ); }
1110
-
1111
- template<typename _Tp> static inline
1112
- Complex<_Tp> operator + (_Tp b, const Complex<_Tp>& a)
1113
- {
1114
- return Complex<_Tp>( a.re + b, a.im );
1115
- }
1116
-
1117
- template<typename _Tp> static inline
1118
- Complex<_Tp> operator - (_Tp b, const Complex<_Tp>& a)
1119
- {
1120
- return Complex<_Tp>( b - a.re, -a.im );
1121
- }
1122
-
1123
- template<typename _Tp> static inline
1124
- Complex<_Tp>& operator += (Complex<_Tp>& a, _Tp b)
1125
- {
1126
- a.re += b; return a;
1127
- }
1128
-
1129
- template<typename _Tp> static inline
1130
- Complex<_Tp>& operator -= (Complex<_Tp>& a, _Tp b)
1131
- {
1132
- a.re -= b; return a;
1133
- }
1134
-
1135
- template<typename _Tp> static inline
1136
- Complex<_Tp>& operator *= (Complex<_Tp>& a, _Tp b)
1137
- {
1138
- a.re *= b; a.im *= b; return a;
1139
- }
1140
-
1141
- template<typename _Tp> static inline
1142
- double abs(const Complex<_Tp>& a)
1143
- {
1144
- return std::sqrt( (double)a.re*a.re + (double)a.im*a.im);
1145
- }
1146
-
1147
- template<typename _Tp> static inline
1148
- Complex<_Tp> operator / (const Complex<_Tp>& a, const Complex<_Tp>& b)
1149
- {
1150
- double t = 1./((double)b.re*b.re + (double)b.im*b.im);
1151
- return Complex<_Tp>( (_Tp)((a.re*b.re + a.im*b.im)*t),
1152
- (_Tp)((-a.re*b.im + a.im*b.re)*t) );
1153
- }
1154
-
1155
- template<typename _Tp> static inline
1156
- Complex<_Tp>& operator /= (Complex<_Tp>& a, const Complex<_Tp>& b)
1157
- {
1158
- a = a / b;
1159
- return a;
1160
- }
1161
-
1162
- template<typename _Tp> static inline
1163
- Complex<_Tp> operator / (const Complex<_Tp>& a, _Tp b)
1164
- {
1165
- _Tp t = (_Tp)1/b;
1166
- return Complex<_Tp>( a.re*t, a.im*t );
1167
- }
1168
-
1169
- template<typename _Tp> static inline
1170
- Complex<_Tp> operator / (_Tp b, const Complex<_Tp>& a)
1171
- {
1172
- return Complex<_Tp>(b)/a;
1173
- }
1174
-
1175
- template<typename _Tp> static inline
1176
- Complex<_Tp> operator /= (const Complex<_Tp>& a, _Tp b)
1177
- {
1178
- _Tp t = (_Tp)1/b;
1179
- a.re *= t; a.im *= t; return a;
1180
- }
1181
-
1182
-
1183
-
1184
- //////////////////////////////// 2D Point ///////////////////////////////
1185
-
1186
- template<typename _Tp> inline
1187
- Point_<_Tp>::Point_()
1188
- : x(0), y(0) {}
1189
-
1190
- template<typename _Tp> inline
1191
- Point_<_Tp>::Point_(_Tp _x, _Tp _y)
1192
- : x(_x), y(_y) {}
1193
-
1194
- #if (defined(__GNUC__) && __GNUC__ < 5) && !defined(__clang__) // GCC 4.x bug. Details: https://github.com/opencv/opencv/pull/20837
1195
- template<typename _Tp> inline
1196
- Point_<_Tp>::Point_(const Point_& pt)
1197
- : x(pt.x), y(pt.y) {}
1198
- #endif
1199
-
1200
- template<typename _Tp> inline
1201
- Point_<_Tp>::Point_(const Size_<_Tp>& sz)
1202
- : x(sz.width), y(sz.height) {}
1203
-
1204
- template<typename _Tp> inline
1205
- Point_<_Tp>::Point_(const Vec<_Tp,2>& v)
1206
- : x(v[0]), y(v[1]) {}
1207
-
1208
- #if (defined(__GNUC__) && __GNUC__ < 5) && !defined(__clang__) // GCC 4.x bug. Details: https://github.com/opencv/opencv/pull/20837
1209
- template<typename _Tp> inline
1210
- Point_<_Tp>& Point_<_Tp>::operator = (const Point_& pt)
1211
- {
1212
- x = pt.x; y = pt.y;
1213
- return *this;
1214
- }
1215
- #endif
1216
-
1217
- template<typename _Tp> template<typename _Tp2> inline
1218
- Point_<_Tp>::operator Point_<_Tp2>() const
1219
- {
1220
- return Point_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y));
1221
- }
1222
-
1223
- template<typename _Tp> inline
1224
- Point_<_Tp>::operator Vec<_Tp, 2>() const
1225
- {
1226
- return Vec<_Tp, 2>(x, y);
1227
- }
1228
-
1229
- template<typename _Tp> inline
1230
- _Tp Point_<_Tp>::dot(const Point_& pt) const
1231
- {
1232
- return saturate_cast<_Tp>(x*pt.x + y*pt.y);
1233
- }
1234
-
1235
- template<typename _Tp> inline
1236
- double Point_<_Tp>::ddot(const Point_& pt) const
1237
- {
1238
- return (double)x*(double)(pt.x) + (double)y*(double)(pt.y);
1239
- }
1240
-
1241
- template<typename _Tp> inline
1242
- double Point_<_Tp>::cross(const Point_& pt) const
1243
- {
1244
- return (double)x*pt.y - (double)y*pt.x;
1245
- }
1246
-
1247
- template<typename _Tp> inline bool
1248
- Point_<_Tp>::inside( const Rect_<_Tp>& r ) const
1249
- {
1250
- return r.contains(*this);
1251
- }
1252
-
1253
-
1254
- template<typename _Tp> static inline
1255
- Point_<_Tp>& operator += (Point_<_Tp>& a, const Point_<_Tp>& b)
1256
- {
1257
- a.x += b.x;
1258
- a.y += b.y;
1259
- return a;
1260
- }
1261
-
1262
- template<typename _Tp> static inline
1263
- Point_<_Tp>& operator -= (Point_<_Tp>& a, const Point_<_Tp>& b)
1264
- {
1265
- a.x -= b.x;
1266
- a.y -= b.y;
1267
- return a;
1268
- }
1269
-
1270
- template<typename _Tp> static inline
1271
- Point_<_Tp>& operator *= (Point_<_Tp>& a, int b)
1272
- {
1273
- a.x = saturate_cast<_Tp>(a.x * b);
1274
- a.y = saturate_cast<_Tp>(a.y * b);
1275
- return a;
1276
- }
1277
-
1278
- template<typename _Tp> static inline
1279
- Point_<_Tp>& operator *= (Point_<_Tp>& a, float b)
1280
- {
1281
- a.x = saturate_cast<_Tp>(a.x * b);
1282
- a.y = saturate_cast<_Tp>(a.y * b);
1283
- return a;
1284
- }
1285
-
1286
- template<typename _Tp> static inline
1287
- Point_<_Tp>& operator *= (Point_<_Tp>& a, double b)
1288
- {
1289
- a.x = saturate_cast<_Tp>(a.x * b);
1290
- a.y = saturate_cast<_Tp>(a.y * b);
1291
- return a;
1292
- }
1293
-
1294
- template<typename _Tp> static inline
1295
- Point_<_Tp>& operator /= (Point_<_Tp>& a, int b)
1296
- {
1297
- a.x = saturate_cast<_Tp>(a.x / b);
1298
- a.y = saturate_cast<_Tp>(a.y / b);
1299
- return a;
1300
- }
1301
-
1302
- template<typename _Tp> static inline
1303
- Point_<_Tp>& operator /= (Point_<_Tp>& a, float b)
1304
- {
1305
- a.x = saturate_cast<_Tp>(a.x / b);
1306
- a.y = saturate_cast<_Tp>(a.y / b);
1307
- return a;
1308
- }
1309
-
1310
- template<typename _Tp> static inline
1311
- Point_<_Tp>& operator /= (Point_<_Tp>& a, double b)
1312
- {
1313
- a.x = saturate_cast<_Tp>(a.x / b);
1314
- a.y = saturate_cast<_Tp>(a.y / b);
1315
- return a;
1316
- }
1317
-
1318
- template<typename _Tp> static inline
1319
- double norm(const Point_<_Tp>& pt)
1320
- {
1321
- return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y);
1322
- }
1323
-
1324
- template<typename _Tp> static inline
1325
- bool operator == (const Point_<_Tp>& a, const Point_<_Tp>& b)
1326
- {
1327
- return a.x == b.x && a.y == b.y;
1328
- }
1329
-
1330
- template<typename _Tp> static inline
1331
- bool operator != (const Point_<_Tp>& a, const Point_<_Tp>& b)
1332
- {
1333
- return a.x != b.x || a.y != b.y;
1334
- }
1335
-
1336
- template<typename _Tp> static inline
1337
- Point_<_Tp> operator + (const Point_<_Tp>& a, const Point_<_Tp>& b)
1338
- {
1339
- return Point_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y) );
1340
- }
1341
-
1342
- template<typename _Tp> static inline
1343
- Point_<_Tp> operator - (const Point_<_Tp>& a, const Point_<_Tp>& b)
1344
- {
1345
- return Point_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y) );
1346
- }
1347
-
1348
- template<typename _Tp> static inline
1349
- Point_<_Tp> operator - (const Point_<_Tp>& a)
1350
- {
1351
- return Point_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y) );
1352
- }
1353
-
1354
- template<typename _Tp> static inline
1355
- Point_<_Tp> operator * (const Point_<_Tp>& a, int b)
1356
- {
1357
- return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) );
1358
- }
1359
-
1360
- template<typename _Tp> static inline
1361
- Point_<_Tp> operator * (int a, const Point_<_Tp>& b)
1362
- {
1363
- return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) );
1364
- }
1365
-
1366
- template<typename _Tp> static inline
1367
- Point_<_Tp> operator * (const Point_<_Tp>& a, float b)
1368
- {
1369
- return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) );
1370
- }
1371
-
1372
- template<typename _Tp> static inline
1373
- Point_<_Tp> operator * (float a, const Point_<_Tp>& b)
1374
- {
1375
- return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) );
1376
- }
1377
-
1378
- template<typename _Tp> static inline
1379
- Point_<_Tp> operator * (const Point_<_Tp>& a, double b)
1380
- {
1381
- return Point_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b) );
1382
- }
1383
-
1384
- template<typename _Tp> static inline
1385
- Point_<_Tp> operator * (double a, const Point_<_Tp>& b)
1386
- {
1387
- return Point_<_Tp>( saturate_cast<_Tp>(b.x*a), saturate_cast<_Tp>(b.y*a) );
1388
- }
1389
-
1390
- template<typename _Tp> static inline
1391
- Point_<_Tp> operator * (const Matx<_Tp, 2, 2>& a, const Point_<_Tp>& b)
1392
- {
1393
- Matx<_Tp, 2, 1> tmp = a * Vec<_Tp,2>(b.x, b.y);
1394
- return Point_<_Tp>(tmp.val[0], tmp.val[1]);
1395
- }
1396
-
1397
- template<typename _Tp> static inline
1398
- Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point_<_Tp>& b)
1399
- {
1400
- Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, 1);
1401
- return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]);
1402
- }
1403
-
1404
- template<typename _Tp> static inline
1405
- Point_<_Tp> operator / (const Point_<_Tp>& a, int b)
1406
- {
1407
- Point_<_Tp> tmp(a);
1408
- tmp /= b;
1409
- return tmp;
1410
- }
1411
-
1412
- template<typename _Tp> static inline
1413
- Point_<_Tp> operator / (const Point_<_Tp>& a, float b)
1414
- {
1415
- Point_<_Tp> tmp(a);
1416
- tmp /= b;
1417
- return tmp;
1418
- }
1419
-
1420
- template<typename _Tp> static inline
1421
- Point_<_Tp> operator / (const Point_<_Tp>& a, double b)
1422
- {
1423
- Point_<_Tp> tmp(a);
1424
- tmp /= b;
1425
- return tmp;
1426
- }
1427
-
1428
-
1429
- template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<int>& pt);
1430
- template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<int64>& pt);
1431
- template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<float>& pt);
1432
- template<typename _AccTp> static inline _AccTp normL2Sqr(const Point_<double>& pt);
1433
-
1434
- template<> inline int normL2Sqr<int>(const Point_<int>& pt) { return pt.dot(pt); }
1435
- template<> inline int64 normL2Sqr<int64>(const Point_<int64>& pt) { return pt.dot(pt); }
1436
- template<> inline float normL2Sqr<float>(const Point_<float>& pt) { return pt.dot(pt); }
1437
- template<> inline double normL2Sqr<double>(const Point_<int>& pt) { return pt.dot(pt); }
1438
-
1439
- template<> inline double normL2Sqr<double>(const Point_<float>& pt) { return pt.ddot(pt); }
1440
- template<> inline double normL2Sqr<double>(const Point_<double>& pt) { return pt.ddot(pt); }
1441
-
1442
-
1443
-
1444
- //////////////////////////////// 3D Point ///////////////////////////////
1445
-
1446
- template<typename _Tp> inline
1447
- Point3_<_Tp>::Point3_()
1448
- : x(0), y(0), z(0) {}
1449
-
1450
- template<typename _Tp> inline
1451
- Point3_<_Tp>::Point3_(_Tp _x, _Tp _y, _Tp _z)
1452
- : x(_x), y(_y), z(_z) {}
1453
-
1454
- template<typename _Tp> inline
1455
- Point3_<_Tp>::Point3_(const Point_<_Tp>& pt)
1456
- : x(pt.x), y(pt.y), z(_Tp()) {}
1457
-
1458
- template<typename _Tp> inline
1459
- Point3_<_Tp>::Point3_(const Vec<_Tp, 3>& v)
1460
- : x(v[0]), y(v[1]), z(v[2]) {}
1461
-
1462
- template<typename _Tp> template<typename _Tp2> inline
1463
- Point3_<_Tp>::operator Point3_<_Tp2>() const
1464
- {
1465
- return Point3_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(z));
1466
- }
1467
-
1468
- template<typename _Tp> inline
1469
- Point3_<_Tp>::operator Vec<_Tp, 3>() const
1470
- {
1471
- return Vec<_Tp, 3>(x, y, z);
1472
- }
1473
-
1474
- template<typename _Tp> inline
1475
- _Tp Point3_<_Tp>::dot(const Point3_& pt) const
1476
- {
1477
- return saturate_cast<_Tp>(x*pt.x + y*pt.y + z*pt.z);
1478
- }
1479
-
1480
- template<typename _Tp> inline
1481
- double Point3_<_Tp>::ddot(const Point3_& pt) const
1482
- {
1483
- return (double)x*pt.x + (double)y*pt.y + (double)z*pt.z;
1484
- }
1485
-
1486
- template<typename _Tp> inline
1487
- Point3_<_Tp> Point3_<_Tp>::cross(const Point3_<_Tp>& pt) const
1488
- {
1489
- return Point3_<_Tp>(y*pt.z - z*pt.y, z*pt.x - x*pt.z, x*pt.y - y*pt.x);
1490
- }
1491
-
1492
-
1493
- template<typename _Tp> static inline
1494
- Point3_<_Tp>& operator += (Point3_<_Tp>& a, const Point3_<_Tp>& b)
1495
- {
1496
- a.x += b.x;
1497
- a.y += b.y;
1498
- a.z += b.z;
1499
- return a;
1500
- }
1501
-
1502
- template<typename _Tp> static inline
1503
- Point3_<_Tp>& operator -= (Point3_<_Tp>& a, const Point3_<_Tp>& b)
1504
- {
1505
- a.x -= b.x;
1506
- a.y -= b.y;
1507
- a.z -= b.z;
1508
- return a;
1509
- }
1510
-
1511
- template<typename _Tp> static inline
1512
- Point3_<_Tp>& operator *= (Point3_<_Tp>& a, int b)
1513
- {
1514
- a.x = saturate_cast<_Tp>(a.x * b);
1515
- a.y = saturate_cast<_Tp>(a.y * b);
1516
- a.z = saturate_cast<_Tp>(a.z * b);
1517
- return a;
1518
- }
1519
-
1520
- template<typename _Tp> static inline
1521
- Point3_<_Tp>& operator *= (Point3_<_Tp>& a, float b)
1522
- {
1523
- a.x = saturate_cast<_Tp>(a.x * b);
1524
- a.y = saturate_cast<_Tp>(a.y * b);
1525
- a.z = saturate_cast<_Tp>(a.z * b);
1526
- return a;
1527
- }
1528
-
1529
- template<typename _Tp> static inline
1530
- Point3_<_Tp>& operator *= (Point3_<_Tp>& a, double b)
1531
- {
1532
- a.x = saturate_cast<_Tp>(a.x * b);
1533
- a.y = saturate_cast<_Tp>(a.y * b);
1534
- a.z = saturate_cast<_Tp>(a.z * b);
1535
- return a;
1536
- }
1537
-
1538
- template<typename _Tp> static inline
1539
- Point3_<_Tp>& operator /= (Point3_<_Tp>& a, int b)
1540
- {
1541
- a.x = saturate_cast<_Tp>(a.x / b);
1542
- a.y = saturate_cast<_Tp>(a.y / b);
1543
- a.z = saturate_cast<_Tp>(a.z / b);
1544
- return a;
1545
- }
1546
-
1547
- template<typename _Tp> static inline
1548
- Point3_<_Tp>& operator /= (Point3_<_Tp>& a, float b)
1549
- {
1550
- a.x = saturate_cast<_Tp>(a.x / b);
1551
- a.y = saturate_cast<_Tp>(a.y / b);
1552
- a.z = saturate_cast<_Tp>(a.z / b);
1553
- return a;
1554
- }
1555
-
1556
- template<typename _Tp> static inline
1557
- Point3_<_Tp>& operator /= (Point3_<_Tp>& a, double b)
1558
- {
1559
- a.x = saturate_cast<_Tp>(a.x / b);
1560
- a.y = saturate_cast<_Tp>(a.y / b);
1561
- a.z = saturate_cast<_Tp>(a.z / b);
1562
- return a;
1563
- }
1564
-
1565
- template<typename _Tp> static inline
1566
- double norm(const Point3_<_Tp>& pt)
1567
- {
1568
- return std::sqrt((double)pt.x*pt.x + (double)pt.y*pt.y + (double)pt.z*pt.z);
1569
- }
1570
-
1571
- template<typename _Tp> static inline
1572
- bool operator == (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1573
- {
1574
- return a.x == b.x && a.y == b.y && a.z == b.z;
1575
- }
1576
-
1577
- template<typename _Tp> static inline
1578
- bool operator != (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1579
- {
1580
- return a.x != b.x || a.y != b.y || a.z != b.z;
1581
- }
1582
-
1583
- template<typename _Tp> static inline
1584
- Point3_<_Tp> operator + (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1585
- {
1586
- return Point3_<_Tp>( saturate_cast<_Tp>(a.x + b.x), saturate_cast<_Tp>(a.y + b.y), saturate_cast<_Tp>(a.z + b.z));
1587
- }
1588
-
1589
- template<typename _Tp> static inline
1590
- Point3_<_Tp> operator - (const Point3_<_Tp>& a, const Point3_<_Tp>& b)
1591
- {
1592
- return Point3_<_Tp>( saturate_cast<_Tp>(a.x - b.x), saturate_cast<_Tp>(a.y - b.y), saturate_cast<_Tp>(a.z - b.z));
1593
- }
1594
-
1595
- template<typename _Tp> static inline
1596
- Point3_<_Tp> operator - (const Point3_<_Tp>& a)
1597
- {
1598
- return Point3_<_Tp>( saturate_cast<_Tp>(-a.x), saturate_cast<_Tp>(-a.y), saturate_cast<_Tp>(-a.z) );
1599
- }
1600
-
1601
- template<typename _Tp> static inline
1602
- Point3_<_Tp> operator * (const Point3_<_Tp>& a, int b)
1603
- {
1604
- return Point3_<_Tp>( saturate_cast<_Tp>(a.x*b), saturate_cast<_Tp>(a.y*b), saturate_cast<_Tp>(a.z*b) );
1605
- }
1606
-
1607
- template<typename _Tp> static inline
1608
- Point3_<_Tp> operator * (int a, const Point3_<_Tp>& b)
1609
- {
1610
- return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) );
1611
- }
1612
-
1613
- template<typename _Tp> static inline
1614
- Point3_<_Tp> operator * (const Point3_<_Tp>& a, float b)
1615
- {
1616
- return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) );
1617
- }
1618
-
1619
- template<typename _Tp> static inline
1620
- Point3_<_Tp> operator * (float a, const Point3_<_Tp>& b)
1621
- {
1622
- return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) );
1623
- }
1624
-
1625
- template<typename _Tp> static inline
1626
- Point3_<_Tp> operator * (const Point3_<_Tp>& a, double b)
1627
- {
1628
- return Point3_<_Tp>( saturate_cast<_Tp>(a.x * b), saturate_cast<_Tp>(a.y * b), saturate_cast<_Tp>(a.z * b) );
1629
- }
1630
-
1631
- template<typename _Tp> static inline
1632
- Point3_<_Tp> operator * (double a, const Point3_<_Tp>& b)
1633
- {
1634
- return Point3_<_Tp>( saturate_cast<_Tp>(b.x * a), saturate_cast<_Tp>(b.y * a), saturate_cast<_Tp>(b.z * a) );
1635
- }
1636
-
1637
- template<typename _Tp> static inline
1638
- Point3_<_Tp> operator * (const Matx<_Tp, 3, 3>& a, const Point3_<_Tp>& b)
1639
- {
1640
- Matx<_Tp, 3, 1> tmp = a * Vec<_Tp,3>(b.x, b.y, b.z);
1641
- return Point3_<_Tp>(tmp.val[0], tmp.val[1], tmp.val[2]);
1642
- }
1643
-
1644
- template<typename _Tp> static inline
1645
- Matx<_Tp, 4, 1> operator * (const Matx<_Tp, 4, 4>& a, const Point3_<_Tp>& b)
1646
- {
1647
- return a * Matx<_Tp, 4, 1>(b.x, b.y, b.z, 1);
1648
- }
1649
-
1650
- template<typename _Tp> static inline
1651
- Point3_<_Tp> operator / (const Point3_<_Tp>& a, int b)
1652
- {
1653
- Point3_<_Tp> tmp(a);
1654
- tmp /= b;
1655
- return tmp;
1656
- }
1657
-
1658
- template<typename _Tp> static inline
1659
- Point3_<_Tp> operator / (const Point3_<_Tp>& a, float b)
1660
- {
1661
- Point3_<_Tp> tmp(a);
1662
- tmp /= b;
1663
- return tmp;
1664
- }
1665
-
1666
- template<typename _Tp> static inline
1667
- Point3_<_Tp> operator / (const Point3_<_Tp>& a, double b)
1668
- {
1669
- Point3_<_Tp> tmp(a);
1670
- tmp /= b;
1671
- return tmp;
1672
- }
1673
-
1674
-
1675
-
1676
- ////////////////////////////////// Size /////////////////////////////////
1677
-
1678
- template<typename _Tp> inline
1679
- Size_<_Tp>::Size_()
1680
- : width(0), height(0) {}
1681
-
1682
- template<typename _Tp> inline
1683
- Size_<_Tp>::Size_(_Tp _width, _Tp _height)
1684
- : width(_width), height(_height) {}
1685
-
1686
- template<typename _Tp> inline
1687
- Size_<_Tp>::Size_(const Point_<_Tp>& pt)
1688
- : width(pt.x), height(pt.y) {}
1689
-
1690
- template<typename _Tp> template<typename _Tp2> inline
1691
- Size_<_Tp>::operator Size_<_Tp2>() const
1692
- {
1693
- return Size_<_Tp2>(saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height));
1694
- }
1695
-
1696
- template<typename _Tp> inline
1697
- _Tp Size_<_Tp>::area() const
1698
- {
1699
- const _Tp result = width * height;
1700
- CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer
1701
- || width == 0 || result / width == height); // make sure the result fits in the return value
1702
- return result;
1703
- }
1704
-
1705
- template<typename _Tp> inline
1706
- double Size_<_Tp>::aspectRatio() const
1707
- {
1708
- return width / static_cast<double>(height);
1709
- }
1710
-
1711
- template<typename _Tp> inline
1712
- bool Size_<_Tp>::empty() const
1713
- {
1714
- return width <= 0 || height <= 0;
1715
- }
1716
-
1717
-
1718
- template<typename _Tp> static inline
1719
- Size_<_Tp>& operator *= (Size_<_Tp>& a, _Tp b)
1720
- {
1721
- a.width *= b;
1722
- a.height *= b;
1723
- return a;
1724
- }
1725
-
1726
- template<typename _Tp> static inline
1727
- Size_<_Tp> operator * (const Size_<_Tp>& a, _Tp b)
1728
- {
1729
- Size_<_Tp> tmp(a);
1730
- tmp *= b;
1731
- return tmp;
1732
- }
1733
-
1734
- template<typename _Tp> static inline
1735
- Size_<_Tp>& operator /= (Size_<_Tp>& a, _Tp b)
1736
- {
1737
- a.width /= b;
1738
- a.height /= b;
1739
- return a;
1740
- }
1741
-
1742
- template<typename _Tp> static inline
1743
- Size_<_Tp> operator / (const Size_<_Tp>& a, _Tp b)
1744
- {
1745
- Size_<_Tp> tmp(a);
1746
- tmp /= b;
1747
- return tmp;
1748
- }
1749
-
1750
- template<typename _Tp> static inline
1751
- Size_<_Tp>& operator += (Size_<_Tp>& a, const Size_<_Tp>& b)
1752
- {
1753
- a.width += b.width;
1754
- a.height += b.height;
1755
- return a;
1756
- }
1757
-
1758
- template<typename _Tp> static inline
1759
- Size_<_Tp> operator + (const Size_<_Tp>& a, const Size_<_Tp>& b)
1760
- {
1761
- Size_<_Tp> tmp(a);
1762
- tmp += b;
1763
- return tmp;
1764
- }
1765
-
1766
- template<typename _Tp> static inline
1767
- Size_<_Tp>& operator -= (Size_<_Tp>& a, const Size_<_Tp>& b)
1768
- {
1769
- a.width -= b.width;
1770
- a.height -= b.height;
1771
- return a;
1772
- }
1773
-
1774
- template<typename _Tp> static inline
1775
- Size_<_Tp> operator - (const Size_<_Tp>& a, const Size_<_Tp>& b)
1776
- {
1777
- Size_<_Tp> tmp(a);
1778
- tmp -= b;
1779
- return tmp;
1780
- }
1781
-
1782
- template<typename _Tp> static inline
1783
- bool operator == (const Size_<_Tp>& a, const Size_<_Tp>& b)
1784
- {
1785
- return a.width == b.width && a.height == b.height;
1786
- }
1787
-
1788
- template<typename _Tp> static inline
1789
- bool operator != (const Size_<_Tp>& a, const Size_<_Tp>& b)
1790
- {
1791
- return !(a == b);
1792
- }
1793
-
1794
-
1795
-
1796
- ////////////////////////////////// Rect /////////////////////////////////
1797
-
1798
- template<typename _Tp> inline
1799
- Rect_<_Tp>::Rect_()
1800
- : x(0), y(0), width(0), height(0) {}
1801
-
1802
- template<typename _Tp> inline
1803
- Rect_<_Tp>::Rect_(_Tp _x, _Tp _y, _Tp _width, _Tp _height)
1804
- : x(_x), y(_y), width(_width), height(_height) {}
1805
-
1806
- template<typename _Tp> inline
1807
- Rect_<_Tp>::Rect_(const Point_<_Tp>& org, const Size_<_Tp>& sz)
1808
- : x(org.x), y(org.y), width(sz.width), height(sz.height) {}
1809
-
1810
- template<typename _Tp> inline
1811
- Rect_<_Tp>::Rect_(const Point_<_Tp>& pt1, const Point_<_Tp>& pt2)
1812
- {
1813
- x = std::min(pt1.x, pt2.x);
1814
- y = std::min(pt1.y, pt2.y);
1815
- width = std::max(pt1.x, pt2.x) - x;
1816
- height = std::max(pt1.y, pt2.y) - y;
1817
- }
1818
-
1819
- template<typename _Tp> inline
1820
- Point_<_Tp> Rect_<_Tp>::tl() const
1821
- {
1822
- return Point_<_Tp>(x,y);
1823
- }
1824
-
1825
- template<typename _Tp> inline
1826
- Point_<_Tp> Rect_<_Tp>::br() const
1827
- {
1828
- return Point_<_Tp>(x + width, y + height);
1829
- }
1830
-
1831
- template<typename _Tp> inline
1832
- Size_<_Tp> Rect_<_Tp>::size() const
1833
- {
1834
- return Size_<_Tp>(width, height);
1835
- }
1836
-
1837
- template<typename _Tp> inline
1838
- _Tp Rect_<_Tp>::area() const
1839
- {
1840
- const _Tp result = width * height;
1841
- CV_DbgAssert(!std::numeric_limits<_Tp>::is_integer
1842
- || width == 0 || result / width == height); // make sure the result fits in the return value
1843
- return result;
1844
- }
1845
-
1846
- template<typename _Tp> inline
1847
- bool Rect_<_Tp>::empty() const
1848
- {
1849
- return width <= 0 || height <= 0;
1850
- }
1851
-
1852
- template<typename _Tp> template<typename _Tp2> inline
1853
- Rect_<_Tp>::operator Rect_<_Tp2>() const
1854
- {
1855
- return Rect_<_Tp2>(saturate_cast<_Tp2>(x), saturate_cast<_Tp2>(y), saturate_cast<_Tp2>(width), saturate_cast<_Tp2>(height));
1856
- }
1857
-
1858
- template<typename _Tp> inline
1859
- bool Rect_<_Tp>::contains(const Point_<_Tp>& pt) const
1860
- {
1861
- return x <= pt.x && pt.x < x + width && y <= pt.y && pt.y < y + height;
1862
- }
1863
-
1864
-
1865
- template<typename _Tp> static inline
1866
- Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Point_<_Tp>& b )
1867
- {
1868
- a.x += b.x;
1869
- a.y += b.y;
1870
- return a;
1871
- }
1872
-
1873
- template<typename _Tp> static inline
1874
- Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Point_<_Tp>& b )
1875
- {
1876
- a.x -= b.x;
1877
- a.y -= b.y;
1878
- return a;
1879
- }
1880
-
1881
- template<typename _Tp> static inline
1882
- Rect_<_Tp>& operator += ( Rect_<_Tp>& a, const Size_<_Tp>& b )
1883
- {
1884
- a.width += b.width;
1885
- a.height += b.height;
1886
- return a;
1887
- }
1888
-
1889
- template<typename _Tp> static inline
1890
- Rect_<_Tp>& operator -= ( Rect_<_Tp>& a, const Size_<_Tp>& b )
1891
- {
1892
- const _Tp width = a.width - b.width;
1893
- const _Tp height = a.height - b.height;
1894
- CV_DbgAssert(width >= 0 && height >= 0);
1895
- a.width = width;
1896
- a.height = height;
1897
- return a;
1898
- }
1899
-
1900
- template<typename _Tp> static inline
1901
- Rect_<_Tp>& operator &= ( Rect_<_Tp>& a, const Rect_<_Tp>& b )
1902
- {
1903
- if (a.empty() || b.empty()) {
1904
- a = Rect();
1905
- return a;
1906
- }
1907
- const Rect_<_Tp>& Rx_min = (a.x < b.x) ? a : b;
1908
- const Rect_<_Tp>& Rx_max = (a.x < b.x) ? b : a;
1909
- const Rect_<_Tp>& Ry_min = (a.y < b.y) ? a : b;
1910
- const Rect_<_Tp>& Ry_max = (a.y < b.y) ? b : a;
1911
- // Looking at the formula below, we will compute Rx_min.width - (Rx_max.x - Rx_min.x)
1912
- // but we want to avoid overflows. Rx_min.width >= 0 and (Rx_max.x - Rx_min.x) >= 0
1913
- // by definition so the difference does not overflow. The only thing that can overflow
1914
- // is (Rx_max.x - Rx_min.x). And it can only overflow if Rx_min.x < 0.
1915
- // Let us first deal with the following case.
1916
- if ((Rx_min.x < 0 && Rx_min.x + Rx_min.width < Rx_max.x) ||
1917
- (Ry_min.y < 0 && Ry_min.y + Ry_min.height < Ry_max.y)) {
1918
- a = Rect();
1919
- return a;
1920
- }
1921
- // We now know that either Rx_min.x >= 0, or
1922
- // Rx_min.x < 0 && Rx_min.x + Rx_min.width >= Rx_max.x and therefore
1923
- // Rx_min.width >= (Rx_max.x - Rx_min.x) which means (Rx_max.x - Rx_min.x)
1924
- // is inferior to a valid int and therefore does not overflow.
1925
- a.width = std::min(Rx_min.width - (Rx_max.x - Rx_min.x), Rx_max.width);
1926
- a.height = std::min(Ry_min.height - (Ry_max.y - Ry_min.y), Ry_max.height);
1927
- a.x = Rx_max.x;
1928
- a.y = Ry_max.y;
1929
- if (a.empty())
1930
- a = Rect();
1931
- return a;
1932
- }
1933
-
1934
- template<typename _Tp> static inline
1935
- Rect_<_Tp>& operator |= ( Rect_<_Tp>& a, const Rect_<_Tp>& b )
1936
- {
1937
- if (a.empty()) {
1938
- a = b;
1939
- }
1940
- else if (!b.empty()) {
1941
- _Tp x1 = std::min(a.x, b.x);
1942
- _Tp y1 = std::min(a.y, b.y);
1943
- a.width = std::max(a.x + a.width, b.x + b.width) - x1;
1944
- a.height = std::max(a.y + a.height, b.y + b.height) - y1;
1945
- a.x = x1;
1946
- a.y = y1;
1947
- }
1948
- return a;
1949
- }
1950
-
1951
- template<typename _Tp> static inline
1952
- bool operator == (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1953
- {
1954
- return a.x == b.x && a.y == b.y && a.width == b.width && a.height == b.height;
1955
- }
1956
-
1957
- template<typename _Tp> static inline
1958
- bool operator != (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1959
- {
1960
- return a.x != b.x || a.y != b.y || a.width != b.width || a.height != b.height;
1961
- }
1962
-
1963
- template<typename _Tp> static inline
1964
- Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Point_<_Tp>& b)
1965
- {
1966
- return Rect_<_Tp>( a.x + b.x, a.y + b.y, a.width, a.height );
1967
- }
1968
-
1969
- template<typename _Tp> static inline
1970
- Rect_<_Tp> operator - (const Rect_<_Tp>& a, const Point_<_Tp>& b)
1971
- {
1972
- return Rect_<_Tp>( a.x - b.x, a.y - b.y, a.width, a.height );
1973
- }
1974
-
1975
- template<typename _Tp> static inline
1976
- Rect_<_Tp> operator + (const Rect_<_Tp>& a, const Size_<_Tp>& b)
1977
- {
1978
- return Rect_<_Tp>( a.x, a.y, a.width + b.width, a.height + b.height );
1979
- }
1980
-
1981
- template<typename _Tp> static inline
1982
- Rect_<_Tp> operator - (const Rect_<_Tp>& a, const Size_<_Tp>& b)
1983
- {
1984
- const _Tp width = a.width - b.width;
1985
- const _Tp height = a.height - b.height;
1986
- CV_DbgAssert(width >= 0 && height >= 0);
1987
- return Rect_<_Tp>( a.x, a.y, width, height );
1988
- }
1989
-
1990
- template<typename _Tp> static inline
1991
- Rect_<_Tp> operator & (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1992
- {
1993
- Rect_<_Tp> c = a;
1994
- return c &= b;
1995
- }
1996
-
1997
- template<typename _Tp> static inline
1998
- Rect_<_Tp> operator | (const Rect_<_Tp>& a, const Rect_<_Tp>& b)
1999
- {
2000
- Rect_<_Tp> c = a;
2001
- return c |= b;
2002
- }
2003
-
2004
- /**
2005
- * @brief measure dissimilarity between two sample sets
2006
- *
2007
- * computes the complement of the Jaccard Index as described in <https://en.wikipedia.org/wiki/Jaccard_index>.
2008
- * For rectangles this reduces to computing the intersection over the union.
2009
- */
2010
- template<typename _Tp> static inline
2011
- double jaccardDistance(const Rect_<_Tp>& a, const Rect_<_Tp>& b) {
2012
- _Tp Aa = a.area();
2013
- _Tp Ab = b.area();
2014
-
2015
- if ((Aa + Ab) <= std::numeric_limits<_Tp>::epsilon()) {
2016
- // jaccard_index = 1 -> distance = 0
2017
- return 0.0;
2018
- }
2019
-
2020
- double Aab = (a & b).area();
2021
- // distance = 1 - jaccard_index
2022
- return 1.0 - Aab / (Aa + Ab - Aab);
2023
- }
2024
-
2025
- /** @brief Finds out if there is any intersection between two rectangles
2026
- *
2027
- * mainly useful for language bindings
2028
- * @param rect1 First rectangle
2029
- * @param rect2 Second rectangle
2030
- * @return the area of the intersection
2031
- */
2032
- CV_EXPORTS_W inline double rectangleIntersectionArea(const Rect2d& a, const Rect2d& b) { return (a & b).area(); }
2033
-
2034
- ////////////////////////////// RotatedRect //////////////////////////////
2035
-
2036
- inline
2037
- RotatedRect::RotatedRect()
2038
- : center(), size(), angle(0) {}
2039
-
2040
- inline
2041
- RotatedRect::RotatedRect(const Point2f& _center, const Size2f& _size, float _angle)
2042
- : center(_center), size(_size), angle(_angle) {}
2043
-
2044
- ///////////////////////////////// Range /////////////////////////////////
2045
-
2046
- inline
2047
- Range::Range()
2048
- : start(0), end(0) {}
2049
-
2050
- inline
2051
- Range::Range(int _start, int _end)
2052
- : start(_start), end(_end) {}
2053
-
2054
- inline
2055
- int Range::size() const
2056
- {
2057
- return end - start;
2058
- }
2059
-
2060
- inline
2061
- bool Range::empty() const
2062
- {
2063
- return start == end;
2064
- }
2065
-
2066
- inline
2067
- Range Range::all()
2068
- {
2069
- return Range(INT_MIN, INT_MAX);
2070
- }
2071
-
2072
-
2073
- static inline
2074
- bool operator == (const Range& r1, const Range& r2)
2075
- {
2076
- return r1.start == r2.start && r1.end == r2.end;
2077
- }
2078
-
2079
- static inline
2080
- bool operator != (const Range& r1, const Range& r2)
2081
- {
2082
- return !(r1 == r2);
2083
- }
2084
-
2085
- static inline
2086
- bool operator !(const Range& r)
2087
- {
2088
- return r.start == r.end;
2089
- }
2090
-
2091
- static inline
2092
- Range operator & (const Range& r1, const Range& r2)
2093
- {
2094
- Range r(std::max(r1.start, r2.start), std::min(r1.end, r2.end));
2095
- r.end = std::max(r.end, r.start);
2096
- return r;
2097
- }
2098
-
2099
- static inline
2100
- Range& operator &= (Range& r1, const Range& r2)
2101
- {
2102
- r1 = r1 & r2;
2103
- return r1;
2104
- }
2105
-
2106
- static inline
2107
- Range operator + (const Range& r1, int delta)
2108
- {
2109
- return Range(r1.start + delta, r1.end + delta);
2110
- }
2111
-
2112
- static inline
2113
- Range operator + (int delta, const Range& r1)
2114
- {
2115
- return Range(r1.start + delta, r1.end + delta);
2116
- }
2117
-
2118
- static inline
2119
- Range operator - (const Range& r1, int delta)
2120
- {
2121
- return r1 + (-delta);
2122
- }
2123
-
2124
-
2125
-
2126
- ///////////////////////////////// Scalar ////////////////////////////////
2127
-
2128
- template<typename _Tp> inline
2129
- Scalar_<_Tp>::Scalar_()
2130
- {
2131
- this->val[0] = this->val[1] = this->val[2] = this->val[3] = 0;
2132
- }
2133
-
2134
- template<typename _Tp> inline
2135
- Scalar_<_Tp>::Scalar_(_Tp v0, _Tp v1, _Tp v2, _Tp v3)
2136
- {
2137
- this->val[0] = v0;
2138
- this->val[1] = v1;
2139
- this->val[2] = v2;
2140
- this->val[3] = v3;
2141
- }
2142
-
2143
- template<typename _Tp> inline
2144
- Scalar_<_Tp>::Scalar_(const Scalar_<_Tp>& s) : Vec<_Tp, 4>(s) {
2145
- }
2146
-
2147
- template<typename _Tp> inline
2148
- Scalar_<_Tp>::Scalar_(Scalar_<_Tp>&& s) CV_NOEXCEPT {
2149
- this->val[0] = std::move(s.val[0]);
2150
- this->val[1] = std::move(s.val[1]);
2151
- this->val[2] = std::move(s.val[2]);
2152
- this->val[3] = std::move(s.val[3]);
2153
- }
2154
-
2155
- template<typename _Tp> inline
2156
- Scalar_<_Tp>& Scalar_<_Tp>::operator=(const Scalar_<_Tp>& s) {
2157
- this->val[0] = s.val[0];
2158
- this->val[1] = s.val[1];
2159
- this->val[2] = s.val[2];
2160
- this->val[3] = s.val[3];
2161
- return *this;
2162
- }
2163
-
2164
- template<typename _Tp> inline
2165
- Scalar_<_Tp>& Scalar_<_Tp>::operator=(Scalar_<_Tp>&& s) CV_NOEXCEPT {
2166
- this->val[0] = std::move(s.val[0]);
2167
- this->val[1] = std::move(s.val[1]);
2168
- this->val[2] = std::move(s.val[2]);
2169
- this->val[3] = std::move(s.val[3]);
2170
- return *this;
2171
- }
2172
-
2173
- template<typename _Tp> template<typename _Tp2, int cn> inline
2174
- Scalar_<_Tp>::Scalar_(const Vec<_Tp2, cn>& v)
2175
- {
2176
- int i;
2177
- for( i = 0; i < (cn < 4 ? cn : 4); i++ )
2178
- this->val[i] = cv::saturate_cast<_Tp>(v.val[i]);
2179
- for( ; i < 4; i++ )
2180
- this->val[i] = 0;
2181
- }
2182
-
2183
- template<typename _Tp> inline
2184
- Scalar_<_Tp>::Scalar_(_Tp v0)
2185
- {
2186
- this->val[0] = v0;
2187
- this->val[1] = this->val[2] = this->val[3] = 0;
2188
- }
2189
-
2190
- template<typename _Tp> inline
2191
- Scalar_<_Tp> Scalar_<_Tp>::all(_Tp v0)
2192
- {
2193
- return Scalar_<_Tp>(v0, v0, v0, v0);
2194
- }
2195
-
2196
-
2197
- template<typename _Tp> inline
2198
- Scalar_<_Tp> Scalar_<_Tp>::mul(const Scalar_<_Tp>& a, double scale ) const
2199
- {
2200
- return Scalar_<_Tp>(saturate_cast<_Tp>(this->val[0] * a.val[0] * scale),
2201
- saturate_cast<_Tp>(this->val[1] * a.val[1] * scale),
2202
- saturate_cast<_Tp>(this->val[2] * a.val[2] * scale),
2203
- saturate_cast<_Tp>(this->val[3] * a.val[3] * scale));
2204
- }
2205
-
2206
- template<typename _Tp> inline
2207
- Scalar_<_Tp> Scalar_<_Tp>::conj() const
2208
- {
2209
- return Scalar_<_Tp>(saturate_cast<_Tp>( this->val[0]),
2210
- saturate_cast<_Tp>(-this->val[1]),
2211
- saturate_cast<_Tp>(-this->val[2]),
2212
- saturate_cast<_Tp>(-this->val[3]));
2213
- }
2214
-
2215
- template<typename _Tp> inline
2216
- bool Scalar_<_Tp>::isReal() const
2217
- {
2218
- return this->val[1] == 0 && this->val[2] == 0 && this->val[3] == 0;
2219
- }
2220
-
2221
-
2222
- template<typename _Tp> template<typename T2> inline
2223
- Scalar_<_Tp>::operator Scalar_<T2>() const
2224
- {
2225
- return Scalar_<T2>(saturate_cast<T2>(this->val[0]),
2226
- saturate_cast<T2>(this->val[1]),
2227
- saturate_cast<T2>(this->val[2]),
2228
- saturate_cast<T2>(this->val[3]));
2229
- }
2230
-
2231
-
2232
- template<typename _Tp> static inline
2233
- Scalar_<_Tp>& operator += (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2234
- {
2235
- a.val[0] += b.val[0];
2236
- a.val[1] += b.val[1];
2237
- a.val[2] += b.val[2];
2238
- a.val[3] += b.val[3];
2239
- return a;
2240
- }
2241
-
2242
- template<typename _Tp> static inline
2243
- Scalar_<_Tp>& operator -= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2244
- {
2245
- a.val[0] -= b.val[0];
2246
- a.val[1] -= b.val[1];
2247
- a.val[2] -= b.val[2];
2248
- a.val[3] -= b.val[3];
2249
- return a;
2250
- }
2251
-
2252
- template<typename _Tp> static inline
2253
- Scalar_<_Tp>& operator *= ( Scalar_<_Tp>& a, _Tp v )
2254
- {
2255
- a.val[0] *= v;
2256
- a.val[1] *= v;
2257
- a.val[2] *= v;
2258
- a.val[3] *= v;
2259
- return a;
2260
- }
2261
-
2262
- template<typename _Tp> static inline
2263
- bool operator == ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b )
2264
- {
2265
- return a.val[0] == b.val[0] && a.val[1] == b.val[1] &&
2266
- a.val[2] == b.val[2] && a.val[3] == b.val[3];
2267
- }
2268
-
2269
- template<typename _Tp> static inline
2270
- bool operator != ( const Scalar_<_Tp>& a, const Scalar_<_Tp>& b )
2271
- {
2272
- return a.val[0] != b.val[0] || a.val[1] != b.val[1] ||
2273
- a.val[2] != b.val[2] || a.val[3] != b.val[3];
2274
- }
2275
-
2276
- template<typename _Tp> static inline
2277
- Scalar_<_Tp> operator + (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2278
- {
2279
- return Scalar_<_Tp>(a.val[0] + b.val[0],
2280
- a.val[1] + b.val[1],
2281
- a.val[2] + b.val[2],
2282
- a.val[3] + b.val[3]);
2283
- }
2284
-
2285
- template<typename _Tp> static inline
2286
- Scalar_<_Tp> operator - (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2287
- {
2288
- return Scalar_<_Tp>(saturate_cast<_Tp>(a.val[0] - b.val[0]),
2289
- saturate_cast<_Tp>(a.val[1] - b.val[1]),
2290
- saturate_cast<_Tp>(a.val[2] - b.val[2]),
2291
- saturate_cast<_Tp>(a.val[3] - b.val[3]));
2292
- }
2293
-
2294
- template<typename _Tp> static inline
2295
- Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, _Tp alpha)
2296
- {
2297
- return Scalar_<_Tp>(a.val[0] * alpha,
2298
- a.val[1] * alpha,
2299
- a.val[2] * alpha,
2300
- a.val[3] * alpha);
2301
- }
2302
-
2303
- template<typename _Tp> static inline
2304
- Scalar_<_Tp> operator * (_Tp alpha, const Scalar_<_Tp>& a)
2305
- {
2306
- return a*alpha;
2307
- }
2308
-
2309
- template<typename _Tp> static inline
2310
- Scalar_<_Tp> operator - (const Scalar_<_Tp>& a)
2311
- {
2312
- return Scalar_<_Tp>(saturate_cast<_Tp>(-a.val[0]),
2313
- saturate_cast<_Tp>(-a.val[1]),
2314
- saturate_cast<_Tp>(-a.val[2]),
2315
- saturate_cast<_Tp>(-a.val[3]));
2316
- }
2317
-
2318
-
2319
- template<typename _Tp> static inline
2320
- Scalar_<_Tp> operator * (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2321
- {
2322
- return Scalar_<_Tp>(saturate_cast<_Tp>(a[0]*b[0] - a[1]*b[1] - a[2]*b[2] - a[3]*b[3]),
2323
- saturate_cast<_Tp>(a[0]*b[1] + a[1]*b[0] + a[2]*b[3] - a[3]*b[2]),
2324
- saturate_cast<_Tp>(a[0]*b[2] - a[1]*b[3] + a[2]*b[0] + a[3]*b[1]),
2325
- saturate_cast<_Tp>(a[0]*b[3] + a[1]*b[2] - a[2]*b[1] + a[3]*b[0]));
2326
- }
2327
-
2328
- template<typename _Tp> static inline
2329
- Scalar_<_Tp>& operator *= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2330
- {
2331
- a = a * b;
2332
- return a;
2333
- }
2334
-
2335
- template<typename _Tp> static inline
2336
- Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, _Tp alpha)
2337
- {
2338
- return Scalar_<_Tp>(a.val[0] / alpha,
2339
- a.val[1] / alpha,
2340
- a.val[2] / alpha,
2341
- a.val[3] / alpha);
2342
- }
2343
-
2344
- template<typename _Tp> static inline
2345
- Scalar_<float> operator / (const Scalar_<float>& a, float alpha)
2346
- {
2347
- float s = 1 / alpha;
2348
- return Scalar_<float>(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s);
2349
- }
2350
-
2351
- template<typename _Tp> static inline
2352
- Scalar_<double> operator / (const Scalar_<double>& a, double alpha)
2353
- {
2354
- double s = 1 / alpha;
2355
- return Scalar_<double>(a.val[0] * s, a.val[1] * s, a.val[2] * s, a.val[3] * s);
2356
- }
2357
-
2358
- template<typename _Tp> static inline
2359
- Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, _Tp alpha)
2360
- {
2361
- a = a / alpha;
2362
- return a;
2363
- }
2364
-
2365
- template<typename _Tp> static inline
2366
- Scalar_<_Tp> operator / (_Tp a, const Scalar_<_Tp>& b)
2367
- {
2368
- _Tp s = a / (b[0]*b[0] + b[1]*b[1] + b[2]*b[2] + b[3]*b[3]);
2369
- return b.conj() * s;
2370
- }
2371
-
2372
- template<typename _Tp> static inline
2373
- Scalar_<_Tp> operator / (const Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2374
- {
2375
- return a * ((_Tp)1 / b);
2376
- }
2377
-
2378
- template<typename _Tp> static inline
2379
- Scalar_<_Tp>& operator /= (Scalar_<_Tp>& a, const Scalar_<_Tp>& b)
2380
- {
2381
- a = a / b;
2382
- return a;
2383
- }
2384
-
2385
- template<typename _Tp> static inline
2386
- Scalar operator * (const Matx<_Tp, 4, 4>& a, const Scalar& b)
2387
- {
2388
- Matx<double, 4, 1> c((Matx<double, 4, 4>)a, b, Matx_MatMulOp());
2389
- return reinterpret_cast<const Scalar&>(c);
2390
- }
2391
-
2392
- template<> inline
2393
- Scalar operator * (const Matx<double, 4, 4>& a, const Scalar& b)
2394
- {
2395
- Matx<double, 4, 1> c(a, b, Matx_MatMulOp());
2396
- return reinterpret_cast<const Scalar&>(c);
2397
- }
2398
-
2399
-
2400
-
2401
- //////////////////////////////// KeyPoint ///////////////////////////////
2402
-
2403
- inline
2404
- KeyPoint::KeyPoint()
2405
- : pt(0,0), size(0), angle(-1), response(0), octave(0), class_id(-1) {}
2406
-
2407
- inline
2408
- KeyPoint::KeyPoint(Point2f _pt, float _size, float _angle, float _response, int _octave, int _class_id)
2409
- : pt(_pt), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {}
2410
-
2411
- inline
2412
- KeyPoint::KeyPoint(float x, float y, float _size, float _angle, float _response, int _octave, int _class_id)
2413
- : pt(x, y), size(_size), angle(_angle), response(_response), octave(_octave), class_id(_class_id) {}
2414
-
2415
-
2416
-
2417
- ///////////////////////////////// DMatch ////////////////////////////////
2418
-
2419
- inline
2420
- DMatch::DMatch()
2421
- : queryIdx(-1), trainIdx(-1), imgIdx(-1), distance(FLT_MAX) {}
2422
-
2423
- inline
2424
- DMatch::DMatch(int _queryIdx, int _trainIdx, float _distance)
2425
- : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(-1), distance(_distance) {}
2426
-
2427
- inline
2428
- DMatch::DMatch(int _queryIdx, int _trainIdx, int _imgIdx, float _distance)
2429
- : queryIdx(_queryIdx), trainIdx(_trainIdx), imgIdx(_imgIdx), distance(_distance) {}
2430
-
2431
- inline
2432
- bool DMatch::operator < (const DMatch &m) const
2433
- {
2434
- return distance < m.distance;
2435
- }
2436
-
2437
-
2438
-
2439
- ////////////////////////////// TermCriteria /////////////////////////////
2440
-
2441
- inline
2442
- TermCriteria::TermCriteria()
2443
- : type(0), maxCount(0), epsilon(0) {}
2444
-
2445
- inline
2446
- TermCriteria::TermCriteria(int _type, int _maxCount, double _epsilon)
2447
- : type(_type), maxCount(_maxCount), epsilon(_epsilon) {}
2448
-
2449
- //! @endcond
2450
-
2451
- } // cv
2452
-
2453
- #ifdef _MSC_VER
2454
- #pragma warning(pop)
2455
- #endif
2456
-
2457
- #endif //OPENCV_CORE_TYPES_HPP