From a66a1a24d7ce9c5a780293a58a6ed679cd041bcf Mon Sep 17 00:00:00 2001 From: Dmitry Kurtaev Date: Sat, 20 Jul 2019 23:26:40 +0300 Subject: [PATCH] Fix drawKeypoints and drawMatches for JS --- modules/js/src/embindgen.py | 4 ++-- modules/js/test/test_features2d.js | 33 ++++++++++++++++++++++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/modules/js/src/embindgen.py b/modules/js/src/embindgen.py index 86f0583329..537bbf529e 100644 --- a/modules/js/src/embindgen.py +++ b/modules/js/src/embindgen.py @@ -141,7 +141,7 @@ features2d = {'Feature2D': ['detect', 'compute', 'detectAndCompute', 'descriptor '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'], - '': ['drawKeypoints', 'drawMatches']} + '': ['drawKeypoints', 'drawMatches', 'drawMatchesKnn']} calib3d = {'': ['findHomography']} @@ -562,7 +562,7 @@ class JSWrapperGenerator(object): match = re.search(r'const std::vector<(.*)>&', arg_type) if match: type_in_vect = match.group(1) - if type_in_vect != 'cv::Mat': + if type_in_vect in ['int', 'float', 'double', 'char', 'uchar', 'String', 'std::string']: casted_arg_name = 'emscripten::vecFromJSArray<' + type_in_vect + '>(' + arg_name + ')' arg_type = re.sub(r'std::vector<(.*)>', 'emscripten::val', arg_type) w_signature.append(arg_type + ' ' + arg_name) diff --git a/modules/js/test/test_features2d.js b/modules/js/test/test_features2d.js index 21982f65f8..173ada0ded 100644 --- a/modules/js/test/test_features2d.js +++ b/modules/js/test/test_features2d.js @@ -80,3 +80,36 @@ QUnit.test('BFMatcher', function(assert) { assert.equal(dm.size(), 67); }); + +QUnit.test('Drawing', function(assert) { + // Generate key points. + let image = generateTestFrame(); + + let kp = new cv.KeyPointVector(); + let descriptors = new cv.Mat(); + let orb = new cv.ORB(); + orb.detectAndCompute(image, new cv.Mat(), kp, descriptors); + assert.equal(kp.size(), 67); + + let dst = new cv.Mat(); + cv.drawKeypoints(image, kp, dst); + assert.equal(dst.rows, image.rows); + assert.equal(dst.cols, image.cols); + + // Run a matcher. + let dm = new cv.DMatchVector(); + let matcher = new cv.BFMatcher(); + matcher.match(descriptors, descriptors, dm); + assert.equal(dm.size(), 67); + + cv.drawMatches(image, kp, image, kp, dm, dst); + assert.equal(dst.rows, image.rows); + assert.equal(dst.cols, 2 * image.cols); + + dm = new cv.DMatchVectorVector(); + matcher.knnMatch(descriptors, descriptors, dm, 2); + assert.equal(dm.size(), 67); + cv.drawMatchesKnn(image, kp, image, kp, dm, dst); + assert.equal(dst.rows, image.rows); + assert.equal(dst.cols, 2 * image.cols); +});