Merge remote-tracking branch 'upstream/3.4' into merge-3.4
[platform/upstream/opencv.git] / modules / js / src / core_bindings.cpp
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) 2013, OpenCV Foundation, all rights reserved.
14 // Third party copyrights are property of their respective owners.
15 //
16 // Redistribution and use in source and binary forms, with or without modification,
17 // are permitted provided that the following conditions are met:
18 //
19 //   * Redistribution's of source code must retain the above copyright notice,
20 //     this list of conditions and the following disclaimer.
21 //
22 //   * Redistribution's in binary form must reproduce the above copyright notice,
23 //     this list of conditions and the following disclaimer in the documentation
24 //     and/or other materials provided with the distribution.
25 //
26 //   * The name of the copyright holders may not be used to endorse or promote products
27 //     derived from this software without specific prior written permission.
28 //
29 // This software is provided by the copyright holders and contributors "as is" and
30 // any express or implied warranties, including, but not limited to, the implied
31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
32 // In no event shall the Intel Corporation or contributors be liable for any direct,
33 // indirect, incidental, special, exemplary, or consequential damages
34 // (including, but not limited to, procurement of substitute goods or services;
35 // loss of use, data, or profits; or business interruption) however caused
36 // and on any theory of liability, whether in contract, strict liability,
37 // or tort (including negligence or otherwise) arising in any way out of
38 // the use of this software, even if advised of the possibility of such damage.
39 //
40 //M*/
41
42 /*M///////////////////////////////////////////////////////////////////////////////////////
43 // Author: Sajjad Taheri, University of California, Irvine. sajjadt[at]uci[dot]edu
44 //
45 //                             LICENSE AGREEMENT
46 // Copyright (c) 2015 The Regents of the University of California (Regents)
47 //
48 // Redistribution and use in source and binary forms, with or without
49 // modification, are permitted provided that the following conditions are met:
50 // 1. Redistributions of source code must retain the above copyright
51 //    notice, this list of conditions and the following disclaimer.
52 // 2. Redistributions in binary form must reproduce the above copyright
53 //    notice, this list of conditions and the following disclaimer in the
54 //    documentation and/or other materials provided with the distribution.
55 // 3. Neither the name of the University nor the
56 //    names of its contributors may be used to endorse or promote products
57 //    derived from this software without specific prior written permission.
58 //
59 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ''AS IS'' AND ANY
60 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
61 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
62 // DISCLAIMED. IN NO EVENT SHALL CONTRIBUTORS BE LIABLE FOR ANY
63 // DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
65 // LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
66 // ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
67 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
68 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
69 //M*/
70
71 #include <emscripten/bind.h>
72
73 @INCLUDES@
74 #include "../../../modules/core/src/parallel_impl.hpp"
75
76 #ifdef TEST_WASM_INTRIN
77 #include "../../../modules/core/include/opencv2/core/hal/intrin.hpp"
78 #include "../../../modules/core/include/opencv2/core/utils/trace.hpp"
79 #include "../../../modules/ts/include/opencv2/ts/ts_gtest.h"
80 namespace cv {
81 namespace hal {
82 #include "../../../modules/core/test/test_intrin_utils.hpp"
83 }
84 }
85 #endif
86
87 using namespace emscripten;
88 using namespace cv;
89
90 #ifdef HAVE_OPENCV_DNN
91 using namespace cv::dnn;
92 #endif
93
94 #ifdef HAVE_OPENCV_ARUCO
95 using namespace aruco;
96 #endif
97
98 namespace binding_utils
99 {
100     template<typename classT, typename enumT>
101     static inline typename std::underlying_type<enumT>::type classT::* underlying_ptr(enumT classT::* enum_ptr)
102     {
103         return reinterpret_cast<typename std::underlying_type<enumT>::type classT::*>(enum_ptr);
104     }
105
106     template<typename T>
107     emscripten::val matData(const cv::Mat& mat)
108     {
109         return emscripten::val(emscripten::memory_view<T>((mat.total()*mat.elemSize())/sizeof(T),
110                                (T*)mat.data));
111     }
112
113     template<typename T>
114     emscripten::val matPtr(const cv::Mat& mat, int i)
115     {
116         return emscripten::val(emscripten::memory_view<T>(mat.step1(0), mat.ptr<T>(i)));
117     }
118
119     template<typename T>
120     emscripten::val matPtr(const cv::Mat& mat, int i, int j)
121     {
122         return emscripten::val(emscripten::memory_view<T>(mat.step1(1), mat.ptr<T>(i,j)));
123     }
124
125     cv::Mat* createMat(int rows, int cols, int type, intptr_t data, size_t step)
126     {
127         return new cv::Mat(rows, cols, type, reinterpret_cast<void*>(data), step);
128     }
129
130     static emscripten::val getMatSize(const cv::Mat& mat)
131     {
132         emscripten::val size = emscripten::val::array();
133         for (int i = 0; i < mat.dims; i++) {
134             size.call<void>("push", mat.size[i]);
135         }
136         return size;
137     }
138
139     static emscripten::val getMatStep(const cv::Mat& mat)
140     {
141         emscripten::val step = emscripten::val::array();
142         for (int i = 0; i < mat.dims; i++) {
143             step.call<void>("push", mat.step[i]);
144         }
145         return step;
146     }
147
148     static Mat matEye(int rows, int cols, int type)
149     {
150         return Mat(cv::Mat::eye(rows, cols, type));
151     }
152
153     static Mat matEye(Size size, int type)
154     {
155         return Mat(cv::Mat::eye(size, type));
156     }
157
158     void convertTo(const Mat& obj, Mat& m, int rtype, double alpha, double beta)
159     {
160         obj.convertTo(m, rtype, alpha, beta);
161     }
162
163     void convertTo(const Mat& obj, Mat& m, int rtype)
164     {
165         obj.convertTo(m, rtype);
166     }
167
168     void convertTo(const Mat& obj, Mat& m, int rtype, double alpha)
169     {
170         obj.convertTo(m, rtype, alpha);
171     }
172
173     Size matSize(const cv::Mat& mat)
174     {
175         return mat.size();
176     }
177
178     cv::Mat matZeros(int arg0, int arg1, int arg2)
179     {
180         return cv::Mat::zeros(arg0, arg1, arg2);
181     }
182
183     cv::Mat matZeros(cv::Size arg0, int arg1)
184     {
185         return cv::Mat::zeros(arg0,arg1);
186     }
187
188     cv::Mat matOnes(int arg0, int arg1, int arg2)
189     {
190         return cv::Mat::ones(arg0, arg1, arg2);
191     }
192
193     cv::Mat matOnes(cv::Size arg0, int arg1)
194     {
195         return cv::Mat::ones(arg0, arg1);
196     }
197
198     double matDot(const cv::Mat& obj, const Mat& mat)
199     {
200         return  obj.dot(mat);
201     }
202
203     Mat matMul(const cv::Mat& obj, const Mat& mat, double scale)
204     {
205         return  Mat(obj.mul(mat, scale));
206     }
207
208     Mat matT(const cv::Mat& obj)
209     {
210         return  Mat(obj.t());
211     }
212
213     Mat matInv(const cv::Mat& obj, int type)
214     {
215         return  Mat(obj.inv(type));
216     }
217
218     void matCopyTo(const cv::Mat& obj, cv::Mat& mat)
219     {
220         return obj.copyTo(mat);
221     }
222
223     void matCopyTo(const cv::Mat& obj, cv::Mat& mat, const cv::Mat& mask)
224     {
225         return obj.copyTo(mat, mask);
226     }
227
228     Mat matDiag(const cv::Mat& obj, int d)
229     {
230         return obj.diag(d);
231     }
232
233     Mat matDiag(const cv::Mat& obj)
234     {
235         return obj.diag();
236     }
237
238     void matSetTo(cv::Mat& obj, const cv::Scalar& s)
239     {
240         obj.setTo(s);
241     }
242
243     void matSetTo(cv::Mat& obj, const cv::Scalar& s, const cv::Mat& mask)
244     {
245         obj.setTo(s, mask);
246     }
247
248     emscripten::val rotatedRectPoints(const cv::RotatedRect& obj)
249     {
250         cv::Point2f points[4];
251         obj.points(points);
252         emscripten::val pointsArray = emscripten::val::array();
253         for (int i = 0; i < 4; i++) {
254             pointsArray.call<void>("push", points[i]);
255         }
256         return pointsArray;
257     }
258
259     Rect rotatedRectBoundingRect(const cv::RotatedRect& obj)
260     {
261         return obj.boundingRect();
262     }
263
264     Rect2f rotatedRectBoundingRect2f(const cv::RotatedRect& obj)
265     {
266         return obj.boundingRect2f();
267     }
268
269     int cvMatDepth(int flags)
270     {
271         return CV_MAT_DEPTH(flags);
272     }
273
274     class MinMaxLoc
275     {
276     public:
277         double minVal;
278         double maxVal;
279         Point minLoc;
280         Point maxLoc;
281     };
282
283     MinMaxLoc minMaxLoc(const cv::Mat& src, const cv::Mat& mask)
284     {
285         MinMaxLoc result;
286         cv::minMaxLoc(src, &result.minVal, &result.maxVal, &result.minLoc, &result.maxLoc, mask);
287         return result;
288     }
289
290     MinMaxLoc minMaxLoc_1(const cv::Mat& src)
291     {
292         MinMaxLoc result;
293         cv::minMaxLoc(src, &result.minVal, &result.maxVal, &result.minLoc, &result.maxLoc);
294         return result;
295     }
296
297     class Circle
298     {
299     public:
300         Point2f center;
301         float radius;
302     };
303
304 #ifdef HAVE_OPENCV_IMGPROC
305     Circle minEnclosingCircle(const cv::Mat& points)
306     {
307         Circle circle;
308         cv::minEnclosingCircle(points, circle.center, circle.radius);
309         return circle;
310     }
311
312     int floodFill_withRect_helper(cv::Mat& arg1, cv::Mat& arg2, Point arg3, Scalar arg4, emscripten::val arg5, Scalar arg6 = Scalar(), Scalar arg7 = Scalar(), int arg8 = 4)
313     {
314         cv::Rect rect;
315
316         int rc = cv::floodFill(arg1, arg2, arg3, arg4, &rect, arg6, arg7, arg8);
317
318         arg5.set("x", emscripten::val(rect.x));
319         arg5.set("y", emscripten::val(rect.y));
320         arg5.set("width", emscripten::val(rect.width));
321         arg5.set("height", emscripten::val(rect.height));
322
323         return rc;
324     }
325
326     int floodFill_wrapper(cv::Mat& arg1, cv::Mat& arg2, Point arg3, Scalar arg4, emscripten::val arg5, Scalar arg6, Scalar arg7, int arg8) {
327         return floodFill_withRect_helper(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8);
328     }
329
330     int floodFill_wrapper_1(cv::Mat& arg1, cv::Mat& arg2, Point arg3, Scalar arg4, emscripten::val arg5, Scalar arg6, Scalar arg7) {
331         return floodFill_withRect_helper(arg1, arg2, arg3, arg4, arg5, arg6, arg7);
332     }
333
334     int floodFill_wrapper_2(cv::Mat& arg1, cv::Mat& arg2, Point arg3, Scalar arg4, emscripten::val arg5, Scalar arg6) {
335         return floodFill_withRect_helper(arg1, arg2, arg3, arg4, arg5, arg6);
336     }
337
338     int floodFill_wrapper_3(cv::Mat& arg1, cv::Mat& arg2, Point arg3, Scalar arg4, emscripten::val arg5) {
339         return floodFill_withRect_helper(arg1, arg2, arg3, arg4, arg5);
340     }
341
342     int floodFill_wrapper_4(cv::Mat& arg1, cv::Mat& arg2, Point arg3, Scalar arg4) {
343         return cv::floodFill(arg1, arg2, arg3, arg4);
344     }
345 #endif
346
347 #ifdef HAVE_OPENCV_VIDEO
348     emscripten::val CamShiftWrapper(const cv::Mat& arg1, Rect& arg2, TermCriteria arg3)
349     {
350         RotatedRect rotatedRect = cv::CamShift(arg1, arg2, arg3);
351         emscripten::val result = emscripten::val::array();
352         result.call<void>("push", rotatedRect);
353         result.call<void>("push", arg2);
354         return result;
355     }
356
357     emscripten::val meanShiftWrapper(const cv::Mat& arg1, Rect& arg2, TermCriteria arg3)
358     {
359         int n = cv::meanShift(arg1, arg2, arg3);
360         emscripten::val result = emscripten::val::array();
361         result.call<void>("push", n);
362         result.call<void>("push", arg2);
363         return result;
364     }
365 #endif  // HAVE_OPENCV_VIDEO
366
367     std::string getExceptionMsg(const cv::Exception& e) {
368         return e.msg;
369     }
370
371     void setExceptionMsg(cv::Exception& e, std::string msg) {
372         e.msg = msg;
373         return;
374     }
375
376     cv::Exception exceptionFromPtr(intptr_t ptr) {
377         return *reinterpret_cast<cv::Exception*>(ptr);
378     }
379
380     std::string getBuildInformation() {
381         return cv::getBuildInformation();
382     }
383
384 #ifdef TEST_WASM_INTRIN
385     void test_hal_intrin_uint8() {
386         cv::hal::test_hal_intrin_uint8();
387     }
388     void test_hal_intrin_int8() {
389         cv::hal::test_hal_intrin_int8();
390     }
391     void test_hal_intrin_uint16() {
392         cv::hal::test_hal_intrin_uint16();
393     }
394     void test_hal_intrin_int16() {
395         cv::hal::test_hal_intrin_int16();
396     }
397     void test_hal_intrin_uint32() {
398         cv::hal::test_hal_intrin_uint32();
399     }
400     void test_hal_intrin_int32() {
401         cv::hal::test_hal_intrin_int32();
402     }
403     void test_hal_intrin_uint64() {
404         cv::hal::test_hal_intrin_uint64();
405     }
406     void test_hal_intrin_int64() {
407         cv::hal::test_hal_intrin_int64();
408     }
409     void test_hal_intrin_float32() {
410         cv::hal::test_hal_intrin_float32();
411     }
412     void test_hal_intrin_float64() {
413         cv::hal::test_hal_intrin_float64();
414     }
415     void test_hal_intrin_all() {
416         cv::hal::test_hal_intrin_uint8();
417         cv::hal::test_hal_intrin_int8();
418         cv::hal::test_hal_intrin_uint16();
419         cv::hal::test_hal_intrin_int16();
420         cv::hal::test_hal_intrin_uint32();
421         cv::hal::test_hal_intrin_int32();
422         cv::hal::test_hal_intrin_uint64();
423         cv::hal::test_hal_intrin_int64();
424         cv::hal::test_hal_intrin_float32();
425         cv::hal::test_hal_intrin_float64();
426     }
427 #endif
428 }
429
430 EMSCRIPTEN_BINDINGS(binding_utils)
431 {
432     register_vector<int>("IntVector");
433     register_vector<float>("FloatVector");
434     register_vector<double>("DoubleVector");
435     register_vector<cv::Point>("PointVector");
436     register_vector<cv::Mat>("MatVector");
437     register_vector<cv::Rect>("RectVector");
438     register_vector<cv::KeyPoint>("KeyPointVector");
439     register_vector<cv::DMatch>("DMatchVector");
440     register_vector<std::vector<cv::DMatch>>("DMatchVectorVector");
441
442
443     emscripten::class_<cv::Mat>("Mat")
444         .constructor<>()
445         .constructor<const Mat&>()
446         .constructor<Size, int>()
447         .constructor<int, int, int>()
448         .constructor<int, int, int, const Scalar&>()
449         .constructor(&binding_utils::createMat, allow_raw_pointers())
450
451         .class_function("eye", select_overload<Mat(Size, int)>(&binding_utils::matEye))
452         .class_function("eye", select_overload<Mat(int, int, int)>(&binding_utils::matEye))
453         .class_function("ones", select_overload<Mat(Size, int)>(&binding_utils::matOnes))
454         .class_function("ones", select_overload<Mat(int, int, int)>(&binding_utils::matOnes))
455         .class_function("zeros", select_overload<Mat(Size, int)>(&binding_utils::matZeros))
456         .class_function("zeros", select_overload<Mat(int, int, int)>(&binding_utils::matZeros))
457
458         .property("rows", &cv::Mat::rows)
459         .property("cols", &cv::Mat::cols)
460         .property("matSize", &binding_utils::getMatSize)
461         .property("step", &binding_utils::getMatStep)
462         .property("data", &binding_utils::matData<unsigned char>)
463         .property("data8S", &binding_utils::matData<char>)
464         .property("data16U", &binding_utils::matData<unsigned short>)
465         .property("data16S", &binding_utils::matData<short>)
466         .property("data32S", &binding_utils::matData<int>)
467         .property("data32F", &binding_utils::matData<float>)
468         .property("data64F", &binding_utils::matData<double>)
469
470         .function("elemSize", select_overload<size_t()const>(&cv::Mat::elemSize))
471         .function("elemSize1", select_overload<size_t()const>(&cv::Mat::elemSize1))
472         .function("channels", select_overload<int()const>(&cv::Mat::channels))
473         .function("convertTo", select_overload<void(const Mat&, Mat&, int, double, double)>(&binding_utils::convertTo))
474         .function("convertTo", select_overload<void(const Mat&, Mat&, int)>(&binding_utils::convertTo))
475         .function("convertTo", select_overload<void(const Mat&, Mat&, int, double)>(&binding_utils::convertTo))
476         .function("total", select_overload<size_t()const>(&cv::Mat::total))
477         .function("row", select_overload<Mat(int)const>(&cv::Mat::row))
478         .function("create", select_overload<void(int, int, int)>(&cv::Mat::create))
479         .function("create", select_overload<void(Size, int)>(&cv::Mat::create))
480         .function("rowRange", select_overload<Mat(int, int)const>(&cv::Mat::rowRange))
481         .function("rowRange", select_overload<Mat(const Range&)const>(&cv::Mat::rowRange))
482         .function("copyTo", select_overload<void(const Mat&, Mat&)>(&binding_utils::matCopyTo))
483         .function("copyTo", select_overload<void(const Mat&, Mat&, const Mat&)>(&binding_utils::matCopyTo))
484         .function("type", select_overload<int()const>(&cv::Mat::type))
485         .function("empty", select_overload<bool()const>(&cv::Mat::empty))
486         .function("colRange", select_overload<Mat(int, int)const>(&cv::Mat::colRange))
487         .function("colRange", select_overload<Mat(const Range&)const>(&cv::Mat::colRange))
488         .function("step1", select_overload<size_t(int)const>(&cv::Mat::step1))
489         .function("clone", select_overload<Mat()const>(&cv::Mat::clone))
490         .function("depth", select_overload<int()const>(&cv::Mat::depth))
491         .function("col", select_overload<Mat(int)const>(&cv::Mat::col))
492         .function("dot", select_overload<double(const Mat&, const Mat&)>(&binding_utils::matDot))
493         .function("mul", select_overload<Mat(const Mat&, const Mat&, double)>(&binding_utils::matMul))
494         .function("inv", select_overload<Mat(const Mat&, int)>(&binding_utils::matInv))
495         .function("t", select_overload<Mat(const Mat&)>(&binding_utils::matT))
496         .function("roi", select_overload<Mat(const Rect&)const>(&cv::Mat::operator()))
497         .function("diag", select_overload<Mat(const Mat&, int)>(&binding_utils::matDiag))
498         .function("diag", select_overload<Mat(const Mat&)>(&binding_utils::matDiag))
499         .function("isContinuous", select_overload<bool()const>(&cv::Mat::isContinuous))
500         .function("setTo", select_overload<void(Mat&, const Scalar&)>(&binding_utils::matSetTo))
501         .function("setTo", select_overload<void(Mat&, const Scalar&, const Mat&)>(&binding_utils::matSetTo))
502         .function("size", select_overload<Size(const Mat&)>(&binding_utils::matSize))
503
504         .function("ptr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<unsigned char>))
505         .function("ptr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<unsigned char>))
506         .function("ucharPtr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<unsigned char>))
507         .function("ucharPtr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<unsigned char>))
508         .function("charPtr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<char>))
509         .function("charPtr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<char>))
510         .function("shortPtr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<short>))
511         .function("shortPtr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<short>))
512         .function("ushortPtr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<unsigned short>))
513         .function("ushortPtr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<unsigned short>))
514         .function("intPtr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<int>))
515         .function("intPtr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<int>))
516         .function("floatPtr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<float>))
517         .function("floatPtr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<float>))
518         .function("doublePtr", select_overload<val(const Mat&, int)>(&binding_utils::matPtr<double>))
519         .function("doublePtr", select_overload<val(const Mat&, int, int)>(&binding_utils::matPtr<double>))
520
521         .function("charAt", select_overload<char&(int)>(&cv::Mat::at<char>))
522         .function("charAt", select_overload<char&(int, int)>(&cv::Mat::at<char>))
523         .function("charAt", select_overload<char&(int, int, int)>(&cv::Mat::at<char>))
524         .function("ucharAt", select_overload<unsigned char&(int)>(&cv::Mat::at<unsigned char>))
525         .function("ucharAt", select_overload<unsigned char&(int, int)>(&cv::Mat::at<unsigned char>))
526         .function("ucharAt", select_overload<unsigned char&(int, int, int)>(&cv::Mat::at<unsigned char>))
527         .function("shortAt", select_overload<short&(int)>(&cv::Mat::at<short>))
528         .function("shortAt", select_overload<short&(int, int)>(&cv::Mat::at<short>))
529         .function("shortAt", select_overload<short&(int, int, int)>(&cv::Mat::at<short>))
530         .function("ushortAt", select_overload<unsigned short&(int)>(&cv::Mat::at<unsigned short>))
531         .function("ushortAt", select_overload<unsigned short&(int, int)>(&cv::Mat::at<unsigned short>))
532         .function("ushortAt", select_overload<unsigned short&(int, int, int)>(&cv::Mat::at<unsigned short>))
533         .function("intAt", select_overload<int&(int)>(&cv::Mat::at<int>) )
534         .function("intAt", select_overload<int&(int, int)>(&cv::Mat::at<int>) )
535         .function("intAt", select_overload<int&(int, int, int)>(&cv::Mat::at<int>) )
536         .function("floatAt", select_overload<float&(int)>(&cv::Mat::at<float>))
537         .function("floatAt", select_overload<float&(int, int)>(&cv::Mat::at<float>))
538         .function("floatAt", select_overload<float&(int, int, int)>(&cv::Mat::at<float>))
539         .function("doubleAt", select_overload<double&(int, int, int)>(&cv::Mat::at<double>))
540         .function("doubleAt", select_overload<double&(int)>(&cv::Mat::at<double>))
541         .function("doubleAt", select_overload<double&(int, int)>(&cv::Mat::at<double>));
542
543     emscripten::value_object<cv::Range>("Range")
544         .field("start", &cv::Range::start)
545         .field("end", &cv::Range::end);
546
547     emscripten::value_object<cv::TermCriteria>("TermCriteria")
548         .field("type", &cv::TermCriteria::type)
549         .field("maxCount", &cv::TermCriteria::maxCount)
550         .field("epsilon", &cv::TermCriteria::epsilon);
551
552 #define EMSCRIPTEN_CV_SIZE(type) \
553     emscripten::value_object<type>("#type") \
554         .field("width", &type::width) \
555         .field("height", &type::height);
556
557     EMSCRIPTEN_CV_SIZE(Size)
558     EMSCRIPTEN_CV_SIZE(Size2f)
559
560 #define EMSCRIPTEN_CV_POINT(type) \
561     emscripten::value_object<type>("#type") \
562         .field("x", &type::x) \
563         .field("y", &type::y); \
564
565     EMSCRIPTEN_CV_POINT(Point)
566     EMSCRIPTEN_CV_POINT(Point2f)
567
568 #define EMSCRIPTEN_CV_RECT(type, name) \
569     emscripten::value_object<cv::Rect_<type>> (name) \
570         .field("x", &cv::Rect_<type>::x) \
571         .field("y", &cv::Rect_<type>::y) \
572         .field("width", &cv::Rect_<type>::width) \
573         .field("height", &cv::Rect_<type>::height);
574
575     EMSCRIPTEN_CV_RECT(int, "Rect")
576     EMSCRIPTEN_CV_RECT(float, "Rect2f")
577
578     emscripten::value_object<cv::RotatedRect>("RotatedRect")
579         .field("center", &cv::RotatedRect::center)
580         .field("size", &cv::RotatedRect::size)
581         .field("angle", &cv::RotatedRect::angle);
582
583     function("rotatedRectPoints", select_overload<emscripten::val(const cv::RotatedRect&)>(&binding_utils::rotatedRectPoints));
584     function("rotatedRectBoundingRect", select_overload<Rect(const cv::RotatedRect&)>(&binding_utils::rotatedRectBoundingRect));
585     function("rotatedRectBoundingRect2f", select_overload<Rect2f(const cv::RotatedRect&)>(&binding_utils::rotatedRectBoundingRect2f));
586
587     emscripten::value_object<cv::KeyPoint>("KeyPoint")
588         .field("angle", &cv::KeyPoint::angle)
589         .field("class_id", &cv::KeyPoint::class_id)
590         .field("octave", &cv::KeyPoint::octave)
591         .field("pt", &cv::KeyPoint::pt)
592         .field("response", &cv::KeyPoint::response)
593         .field("size", &cv::KeyPoint::size);
594
595     emscripten::value_object<cv::DMatch>("DMatch")
596         .field("queryIdx", &cv::DMatch::queryIdx)
597         .field("trainIdx", &cv::DMatch::trainIdx)
598         .field("imgIdx", &cv::DMatch::imgIdx)
599         .field("distance", &cv::DMatch::distance);
600
601     emscripten::value_array<cv::Scalar_<double>> ("Scalar")
602         .element(emscripten::index<0>())
603         .element(emscripten::index<1>())
604         .element(emscripten::index<2>())
605         .element(emscripten::index<3>());
606
607     emscripten::value_object<binding_utils::MinMaxLoc>("MinMaxLoc")
608         .field("minVal", &binding_utils::MinMaxLoc::minVal)
609         .field("maxVal", &binding_utils::MinMaxLoc::maxVal)
610         .field("minLoc", &binding_utils::MinMaxLoc::minLoc)
611         .field("maxLoc", &binding_utils::MinMaxLoc::maxLoc);
612
613     emscripten::value_object<binding_utils::Circle>("Circle")
614         .field("center", &binding_utils::Circle::center)
615         .field("radius", &binding_utils::Circle::radius);
616
617     emscripten::value_object<cv::Moments >("Moments")
618         .field("m00", &cv::Moments::m00)
619         .field("m10", &cv::Moments::m10)
620         .field("m01", &cv::Moments::m01)
621         .field("m20", &cv::Moments::m20)
622         .field("m11", &cv::Moments::m11)
623         .field("m02", &cv::Moments::m02)
624         .field("m30", &cv::Moments::m30)
625         .field("m21", &cv::Moments::m21)
626         .field("m12", &cv::Moments::m12)
627         .field("m03", &cv::Moments::m03)
628         .field("mu20", &cv::Moments::mu20)
629         .field("mu11", &cv::Moments::mu11)
630         .field("mu02", &cv::Moments::mu02)
631         .field("mu30", &cv::Moments::mu30)
632         .field("mu21", &cv::Moments::mu21)
633         .field("mu12", &cv::Moments::mu12)
634         .field("mu03", &cv::Moments::mu03)
635         .field("nu20", &cv::Moments::nu20)
636         .field("nu11", &cv::Moments::nu11)
637         .field("nu02", &cv::Moments::nu02)
638         .field("nu30", &cv::Moments::nu30)
639         .field("nu21", &cv::Moments::nu21)
640         .field("nu12", &cv::Moments::nu12)
641         .field("nu03", &cv::Moments::nu03);
642
643     emscripten::value_object<cv::Exception>("Exception")
644         .field("code", &cv::Exception::code)
645         .field("msg", &binding_utils::getExceptionMsg, &binding_utils::setExceptionMsg);
646
647     function("exceptionFromPtr", &binding_utils::exceptionFromPtr, allow_raw_pointers());
648
649 #ifdef HAVE_OPENCV_IMGPROC
650     function("minEnclosingCircle", select_overload<binding_utils::Circle(const cv::Mat&)>(&binding_utils::minEnclosingCircle));
651
652     function("floodFill", select_overload<int(cv::Mat&, cv::Mat&, Point, Scalar, emscripten::val, Scalar, Scalar, int)>(&binding_utils::floodFill_wrapper));
653
654     function("floodFill", select_overload<int(cv::Mat&, cv::Mat&, Point, Scalar, emscripten::val, Scalar, Scalar)>(&binding_utils::floodFill_wrapper_1));
655
656     function("floodFill", select_overload<int(cv::Mat&, cv::Mat&, Point, Scalar, emscripten::val, Scalar)>(&binding_utils::floodFill_wrapper_2));
657
658     function("floodFill", select_overload<int(cv::Mat&, cv::Mat&, Point, Scalar, emscripten::val)>(&binding_utils::floodFill_wrapper_3));
659
660     function("floodFill", select_overload<int(cv::Mat&, cv::Mat&, Point, Scalar)>(&binding_utils::floodFill_wrapper_4));
661 #endif
662
663     function("minMaxLoc", select_overload<binding_utils::MinMaxLoc(const cv::Mat&, const cv::Mat&)>(&binding_utils::minMaxLoc));
664
665     function("minMaxLoc", select_overload<binding_utils::MinMaxLoc(const cv::Mat&)>(&binding_utils::minMaxLoc_1));
666
667 #ifdef HAVE_OPENCV_IMGPROC
668     function("morphologyDefaultBorderValue", &cv::morphologyDefaultBorderValue);
669 #endif
670
671     function("CV_MAT_DEPTH", &binding_utils::cvMatDepth);
672
673 #ifdef HAVE_OPENCV_VIDEO
674     function("CamShift", select_overload<emscripten::val(const cv::Mat&, Rect&, TermCriteria)>(&binding_utils::CamShiftWrapper));
675
676     function("meanShift", select_overload<emscripten::val(const cv::Mat&, Rect&, TermCriteria)>(&binding_utils::meanShiftWrapper));
677 #endif
678
679     function("getBuildInformation", &binding_utils::getBuildInformation);
680
681 #ifdef HAVE_PTHREADS_PF
682     function("parallel_pthreads_set_threads_num", &cv::parallel_pthreads_set_threads_num);
683     function("parallel_pthreads_get_threads_num", &cv::parallel_pthreads_get_threads_num);
684 #endif
685
686 #ifdef TEST_WASM_INTRIN
687     function("test_hal_intrin_uint8", &binding_utils::test_hal_intrin_uint8);
688     function("test_hal_intrin_int8", &binding_utils::test_hal_intrin_int8);
689     function("test_hal_intrin_uint16", &binding_utils::test_hal_intrin_uint16);
690     function("test_hal_intrin_int16", &binding_utils::test_hal_intrin_int16);
691     function("test_hal_intrin_uint32", &binding_utils::test_hal_intrin_uint32);
692     function("test_hal_intrin_int32", &binding_utils::test_hal_intrin_int32);
693     function("test_hal_intrin_uint64", &binding_utils::test_hal_intrin_uint64);
694     function("test_hal_intrin_int64", &binding_utils::test_hal_intrin_int64);
695     function("test_hal_intrin_float32", &binding_utils::test_hal_intrin_float32);
696     function("test_hal_intrin_float64", &binding_utils::test_hal_intrin_float64);
697     function("test_hal_intrin_all", &binding_utils::test_hal_intrin_all);
698 #endif
699
700     constant("CV_8UC1", CV_8UC1);
701     constant("CV_8UC2", CV_8UC2);
702     constant("CV_8UC3", CV_8UC3);
703     constant("CV_8UC4", CV_8UC4);
704
705     constant("CV_8SC1", CV_8SC1);
706     constant("CV_8SC2", CV_8SC2);
707     constant("CV_8SC3", CV_8SC3);
708     constant("CV_8SC4", CV_8SC4);
709
710     constant("CV_16UC1", CV_16UC1);
711     constant("CV_16UC2", CV_16UC2);
712     constant("CV_16UC3", CV_16UC3);
713     constant("CV_16UC4", CV_16UC4);
714
715     constant("CV_16SC1", CV_16SC1);
716     constant("CV_16SC2", CV_16SC2);
717     constant("CV_16SC3", CV_16SC3);
718     constant("CV_16SC4", CV_16SC4);
719
720     constant("CV_32SC1", CV_32SC1);
721     constant("CV_32SC2", CV_32SC2);
722     constant("CV_32SC3", CV_32SC3);
723     constant("CV_32SC4", CV_32SC4);
724
725     constant("CV_32FC1", CV_32FC1);
726     constant("CV_32FC2", CV_32FC2);
727     constant("CV_32FC3", CV_32FC3);
728     constant("CV_32FC4", CV_32FC4);
729
730     constant("CV_64FC1", CV_64FC1);
731     constant("CV_64FC2", CV_64FC2);
732     constant("CV_64FC3", CV_64FC3);
733     constant("CV_64FC4", CV_64FC4);
734
735     constant("CV_8U", CV_8U);
736     constant("CV_8S", CV_8S);
737     constant("CV_16U", CV_16U);
738     constant("CV_16S", CV_16S);
739     constant("CV_32S",  CV_32S);
740     constant("CV_32F", CV_32F);
741     constant("CV_64F", CV_64F);
742
743     constant("INT_MIN", INT_MIN);
744     constant("INT_MAX", INT_MAX);
745 }