From e9f99063c70699e48a7589f2958b348189d3b494 Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Wed, 26 Sep 2018 19:11:40 +0300 Subject: [PATCH] JavaScript bindings for features2d module --- modules/features2d/CMakeLists.txt | 2 +- .../features2d/include/opencv2/features2d.hpp | 4 +++ modules/js/src/embindgen.py | 27 ++++++++++++++----- platforms/js/build_js.py | 2 +- 4 files changed, 27 insertions(+), 8 deletions(-) diff --git a/modules/features2d/CMakeLists.txt b/modules/features2d/CMakeLists.txt index 2a6456f69b..f18f69edb3 100644 --- a/modules/features2d/CMakeLists.txt +++ b/modules/features2d/CMakeLists.txt @@ -1,2 +1,2 @@ set(the_description "2D Features Framework") -ocv_define_module(features2d opencv_imgproc OPTIONAL opencv_flann opencv_highgui WRAP java python) +ocv_define_module(features2d opencv_imgproc OPTIONAL opencv_flann opencv_highgui WRAP java python js) diff --git a/modules/features2d/include/opencv2/features2d.hpp b/modules/features2d/include/opencv2/features2d.hpp index 1ba4f0da26..ee81ebe385 100644 --- a/modules/features2d/include/opencv2/features2d.hpp +++ b/modules/features2d/include/opencv2/features2d.hpp @@ -137,7 +137,11 @@ public: /** @brief Abstract base class for 2D image feature detectors and descriptor extractors */ +#ifdef __EMSCRIPTEN__ +class CV_EXPORTS_W Feature2D : public Algorithm +#else class CV_EXPORTS_W Feature2D : public virtual Algorithm +#endif { public: virtual ~Feature2D(); diff --git a/modules/js/src/embindgen.py b/modules/js/src/embindgen.py index 2e9811ada2..caa8d6067e 100644 --- a/modules/js/src/embindgen.py +++ b/modules/js/src/embindgen.py @@ -126,7 +126,22 @@ video = {'': ['CamShift', 'calcOpticalFlowFarneback', 'calcOpticalFlowPyrLK', 'c 'BackgroundSubtractor': ['apply', 'getBackgroundImage']} dnn = {'dnn_Net': ['setInput', 'forward'], - '': ['readNetFromCaffe', 'readNetFromTensorflow', 'readNetFromTorch', 'readNetFromDarknet', 'blobFromImage']} + '': ['readNetFromCaffe', 'readNetFromTensorflow', 'readNetFromTorch', 'readNetFromDarknet', + 'readNetFromONNX', 'readNet', 'blobFromImage']} + +features2d = {'Feature2D': ['detect', 'compute', 'detectAndCompute', 'descriptorSize', 'descriptorType', 'defaultNorm', 'empty', 'getDefaultName'], + 'BRISK': ['create', 'getDefaultName'], + 'ORB': ['create', 'setMaxFeatures', 'setScaleFactor', 'setNLevels', 'setEdgeThreshold', 'setFirstLevel', 'setWTA_K', 'setScoreType', 'setPatchSize', 'getFastThreshold', 'getDefaultName'], + 'MSER': ['create', 'detectRegions', 'setDelta', 'getDelta', 'setMinArea', 'getMinArea', 'setMaxArea', 'getMaxArea', 'setPass2Only', 'getPass2Only', 'getDefaultName'], + 'FastFeatureDetector': ['create', 'setThreshold', 'getThreshold', 'setNonmaxSuppression', 'getNonmaxSuppression', 'setType', 'getType', 'getDefaultName'], + 'AgastFeatureDetector': ['create', 'setThreshold', 'getThreshold', 'setNonmaxSuppression', 'getNonmaxSuppression', 'setType', 'getType', 'getDefaultName'], + 'GFTTDetector': ['create', 'setMaxFeatures', 'getMaxFeatures', 'setQualityLevel', 'getQualityLevel', 'setMinDistance', 'getMinDistance', 'setBlockSize', 'getBlockSize', 'setHarrisDetector', 'getHarrisDetector', 'setK', 'getK', 'getDefaultName'], + # 'SimpleBlobDetector': ['create'], + 'KAZE': ['create', 'setExtended', 'getExtended', 'setUpright', 'getUpright', 'setThreshold', 'getThreshold', 'setNOctaves', 'getNOctaves', 'setNOctaveLayers', 'getNOctaveLayers', 'setDiffusivity', 'getDiffusivity', 'getDefaultName'], + 'AKAZE': ['create', 'setDescriptorType', 'getDescriptorType', 'setDescriptorSize', 'getDescriptorSize', 'setDescriptorChannels', 'getDescriptorChannels', 'setThreshold', 'getThreshold', 'setNOctaves', 'getNOctaves', 'setNOctaveLayers', 'getNOctaveLayers', 'setDiffusivity', 'getDiffusivity', 'getDefaultName'], + 'DescriptorMatcher': ['add', 'clear', 'empty', 'isMaskSupported', 'train', 'match', 'knnMatch', 'radiusMatch', 'clone', 'create'], + 'BFMatcher': ['isMaskSupported', 'create'], + '': ['FAST', 'AGAST', 'drawKeypoints', 'drawMatches']} def makeWhiteList(module_list): wl = {} @@ -138,7 +153,7 @@ def makeWhiteList(module_list): wl[k] = m[k] return wl -white_list = makeWhiteList([core, imgproc, objdetect, video, dnn]) +white_list = makeWhiteList([core, imgproc, objdetect, video, dnn, features2d]) # Features to be exported export_enums = False @@ -219,7 +234,8 @@ def handle_ptr(tp): def handle_vector(tp): if tp.startswith('vector_'): - tp = 'std::vector<' + "::".join(tp.split('_')[1:]) + '>' + tp = handle_vector(tp[tp.find('_') + 1:]) + tp = 'std::vector<' + "::".join(tp.split('_')) + '>' return tp @@ -845,13 +861,12 @@ class JSWrapperGenerator(object): [class_info.cname, property.name]))) dv = '' - base = Template("""base<$base$isPoly>""") + base = Template("""base<$base>""") assert len(class_info.bases) <= 1 , "multiple inheritance not supported" if len(class_info.bases) == 1: - dv = "," + base.substitute(base=', '.join(class_info.bases), - isPoly = " ,true" if class_info.name=="Feature2D" else "") + dv = "," + base.substitute(base=', '.join(class_info.bases)) self.bindings.append(class_template.substitute(cpp_name=class_info.cname, js_name=name, diff --git a/platforms/js/build_js.py b/platforms/js/build_js.py index 3ff69c05e5..3cdce4aa2b 100644 --- a/platforms/js/build_js.py +++ b/platforms/js/build_js.py @@ -131,7 +131,7 @@ class Builder: "-DBUILD_opencv_apps=OFF", "-DBUILD_opencv_calib3d=OFF", "-DBUILD_opencv_dnn=ON", - "-DBUILD_opencv_features2d=OFF", + "-DBUILD_opencv_features2d=ON", "-DBUILD_opencv_flann=OFF", "-DBUILD_opencv_ml=OFF", "-DBUILD_opencv_photo=OFF",