Skip to content

Add tests for features2d JavaScript bindings - #12855

Merged
opencv-pushbot merged 1 commit into
opencv:3.4from
dkurt:js_features2d_tests
Feb 2, 2019
Merged

opencv-pushbot merged 1 commit into
opencv:3.4from
dkurt:js_features2d_tests

Conversation

@dkurt

@dkurt dkurt commented Oct 16, 2018 •

Copy link
Copy Markdown
Member

This pullrequest changes

resolves #12706

  • DMatch definition
  • tests
docker_image:Docs=docs-js
docker_image:Custom=javascript
buildworker:Docs=linux-1
buildworker:Custom=linux-1

@dkurt
dkurt force-pushed the js_features2d_tests branch 2 times, most recently from ddc04b8 to 683a5d3 Compare October 16, 2018 10:48
@dkurt

dkurt commented Oct 18, 2018

Copy link
Copy Markdown
Member Author

The test numbers are received from python bindings:

import cv2 as cv
import numpy as np

image = np.zeros([100, 100], np.uint8)

cv.setRNGSeed(324)
cv.randu(image, 0, 255)

orb = cv.ORB_create()
kp = orb.detect(image)
print(len(kp))

mser = cv.MSER_create()
kp = mser.detect(image)
print(len(kp))

brisk = cv.BRISK_create()
kp = brisk.detect(image)
print(len(kp))

ffd = cv.FastFeatureDetector_create()
kp = ffd.detect(image)
print(len(kp))

afd = cv.AgastFeatureDetector_create()
kp = afd.detect(image)
print(len(kp))

gftt = cv.GFTTDetector_create()
kp = gftt.detect(image)
print(len(kp))

kaze = cv.KAZE_create()
kp = kaze.detect(image)
print(len(kp))

akaze = cv.AKAZE_create()
kp = akaze.detect(image)
print(len(kp))

@dkurt

dkurt commented Oct 19, 2018

Copy link
Copy Markdown
Member Author

@huningxin, May I ask you how to debug emscripten compilation?
The problem is that using the latest versions (i.e. 1.38.13) one of our tests is failed:

cv.max(mat1, mat2, mat3);
// Verify result.
size = mat2.size();
assert.equal(mat2.channels(), 1);
assert.equal(size.height, 3);
assert.equal(size.width, 3);
assert.deepEqual(mat3.data, expectedMax);

I found that the following loop is a source of wrong values in src2:

#if CV_ENABLE_UNROLLED
for( ; x <= width - 4; x += 4 )
{
T v0 = op(src1[x], src2[x]);
T v1 = op(src1[x+1], src2[x+1]);
dst[x] = v0; dst[x+1] = v1;
v0 = op(src1[x+2], src2[x+2]);
v1 = op(src1[x+3], src2[x+3]);
dst[x+2] = v0; dst[x+3] = v1;
}
#endif

Comment thread modules/js/test/test_features2d.js Outdated
let image = new cv.Mat(100, 100, cv.CV_8UC1);
let low = new cv.Mat(1, 1, cv.CV_8UC1, [0, 0, 0, 0]);
let high = new cv.Mat(1, 1, cv.CV_8UC1, [255, 255, 255, 255]);
cv.randu(image, low, high);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Avoid using of random images for keypoint detectors. Their implementations are not stable (not bit-exact between platforms).

Try to generate some synthetic frame instead:

function generateTestFrame(width, height) {
  let w = width || 200;
  let h = height || 200;
  let img = new cv.Mat(h, w, cv.CV_8UC1, new cv.Scalar(0, 0, 0, 0));
  let s0 = new cv.Scalar(0, 0, 0, 0);
  let s = new cv.Scalar(255, 255, 255, 255);
  let s128 = new cv.Scalar(128, 128, 128, 128);
  let rect = new cv.Rect(w / 4, h / 4, w / 2, h / 2);
  img.roi(rect).setTo(s);
  img.roi(new cv.Rect(w / 2 - w / 8, h / 2 - h / 8, w / 4, h / 4)).setTo(s128);
  cv.rectangle(img, new cv.Point(w / 8, h / 8), new cv.Point(w - w / 8, h - h / 8), s, 5);
  cv.rectangle(img, new cv.Point(w / 5, h / 5), new cv.Point(w - w / 5, h - h / 5), s128, 3);
  cv.line(img, new cv.Point(-w, 0), new cv.Point(w / 2, h / 2), s128, 5);
  cv.line(img, new cv.Point(2*w, 0), new cv.Point(w / 2, h / 2), s, 5);
  return img;
}

...
    let image = generateTestFrame();
  1. "low", "high" are not used.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you! Done

Comment thread platforms/js/build_js.py
"-DWITH_GPHOTO2=OFF",
"-DWITH_LAPACK=OFF",
"-DWITH_ITT=OFF",
"-DWITH_QUIRC=OFF",

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is it changed?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

quirc is a dependency of QRCodeDetector which has no wrappers yet.

class CV_EXPORTS QRCodeDetector

@allnes, Could you wrap it to python/java and add to the following file for JS bindings:
objdetect = {'': ['groupRectangles'],
'HOGDescriptor': ['load', 'HOGDescriptor', 'getDefaultPeopleDetector', 'getDaimlerPeopleDetector', 'setSVMDetector', 'detectMultiScale'],
'CascadeClassifier': ['load', 'detectMultiScale2', 'CascadeClassifier', 'detectMultiScale3', 'empty', 'detectMultiScale']}

@huningxin

Copy link
Copy Markdown
Contributor

Thank you folks! I am attending conference this week. The response is slow. Sorry for that.

@huningxin

Copy link
Copy Markdown
Contributor

@sajjadt, are you able to take a look? Thanks!

@dkurt

dkurt commented Dec 24, 2018

Copy link
Copy Markdown
Member Author

@alalek, @huningxin, It looks like the problem is solved. I tried to build this branch with emscripten 1.38.21 and all the tests are passed.

@alalek

alalek commented Dec 27, 2018

Copy link
Copy Markdown
Member

Updated emscipten on linux-1: 1.38.21

Tests fails with latest LTS version of node (10.15.0), so downgraded on previous --lts=carbon (https://github.com/nodejs/Release):

+ node --version
v8.15.0
+ npm --version
6.4.1

@dkurt
dkurt force-pushed the js_features2d_tests branch from 05665f3 to 8ecc5e6 Compare February 1, 2019 16:15

@alalek alalek left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well done! Thank you 👍

@opencv-pushbot
opencv-pushbot merged commit 8ecc5e6 into opencv:3.4 Feb 2, 2019
@alalek alalek mentioned this pull request Feb 5, 2019
SavyaSanchi-Sharma pushed a commit to SavyaSanchi-Sharma/opencv that referenced this pull request Jul 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants