Skip to content

Add QRCodeDetector to JavaScript Build#19284

Merged
alalek merged 5 commits intoopencv:3.4from
Ziachnix:feature/js-qr-code-detector
Mar 13, 2021
Merged

Add QRCodeDetector to JavaScript Build#19284
alalek merged 5 commits intoopencv:3.4from
Ziachnix:feature/js-qr-code-detector

Conversation

@Ziachnix
Copy link
Copy Markdown
Contributor

@Ziachnix Ziachnix commented Jan 7, 2021

This PR adds javascript support for the class QRCodeDetector.
Tests for the proposed functions are derived from the equivalent python tests.
Because sample images are needed for running the tests, the build of the tests
requires now the opencv_extra repository.
(Alternatively i could copy some test images into the tutorial folder and use
them in the tests)
Due to emscripten limitations the functions decodeMulti and
detectAndDecodeMulti are excluded.
As far as i know it is not possible to use a function parameter (string array)
to return the decoded content of the QR codes.

Pull Request Readiness Checklist

See details at https://github.com/opencv/opencv/wiki/How_to_contribute#making-a-good-pull-request

  • I agree to contribute to the project under Apache 2 License.
  • To the best of my knowledge, the proposed patch is not based on a code under GPL or other license that is incompatible with OpenCV
  • The PR is proposed to proper branch
  • There is reference to original bug report and related work
  • There is accuracy test, performance test and test data in opencv_extra repository, if applicable
    Patch to opencv_extra has the same branch name.
  • The feature is well documented and sample code can be built with the project CMake
force_builders=Custom
build_image:Docs=docs-js
buildworker:Docs=linux-4,linux-6
build_image:Custom=javascript
buildworker:Custom=linux-4

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Thank you for contribution!

Please take a look on comments below.

@endcode

@note
It requires the [opencv_extra repository](https://github.com/opencv/opencv.git) located in your development environment.
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.

Lets keep OPENCV_TEST_DATA_PATH optional.

Prefer to use environment variable for OPENCV_TEST_DATA_PATH.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Did i get you right, that the tests for the QRCodeDetector should be skipped when the enviroment variable OPENCV_TEST_DATA_PATH is not set? Because the tests depend on two files from the opencv_extra repository.

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.

Right

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.

Please drop OPENCV_TEST_DATA_PATH changes from the patch

list(APPEND opencv_test_js_file_deps "${test_data_haarcascade_path}" "${opencv_test_js_bin_dir}/${test_data_haarcascade}")
# QR code
set(test_data_qrcode_1 "link_ocv.jpg")
set(test_data_qrcode_1_path "${OPENCV_TEST_DATA_PATH}/cv/qrcode/${test_data_qrcode_1}")
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.

Copy data only if build_tests enabled.

Comment on lines 122 to 123
'string':'std::string', # Side effect
'String': 'std::string',
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.

Keep existed coding style.

Please remove the comment as it doesn't help and just confuse readers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thank you, i will remove the comment and fix the coding style.
If you swap the order of the entry 'string': 'std::string' (line 122) with 'String': 'std::string' (line 123) a double replacement happens and the code doesn't work anymore.
Should i add a comment there with a warning to not swap the order of the entries?

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.

Thank you for information! I will take a look on this behavior

Comment on lines +169 to +172
const imgSingleQrCode = new Image();
imgSingleQrCode.crossOrigin = 'anonymous';
imgSingleQrCode.onload = function () {
const canvas = document.createElement('canvas');
const ctx = canvas.getContext('2d');
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.

Does it work in Node.JS ?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right, this is not working in Node.js.
In order to provide tests i have seen other JavaScript tests, where images are created from a hardcoded array.
In this test case it would probably be a huge array to create an image containing a QR-code.
Is there a way of loading images, which works both in the browser and in node.js? Otherwise i have to implement two different ways of loading the images.

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.

Until we have good images (testdata) support in JS tests infrastructure, lets check the "bindings" existence only (without any attempt to perform accuracy checks).

Please use Mat.zeros(...) as input in tests for now. And check that there are no exceptions raised. Minimal smoke test.

For accuracy demo it would be nice to add tutorial page (examples).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I have now added tests that do not require any test images.
Therefore I have removed the copying of the test images again.
I will start writing a tutorial page. Should the tutorial include the QR code recognition algorithm? As far as I could understand QrCodeDetector::detect uses the algorithm described in this article.

@Ziachnix Ziachnix force-pushed the feature/js-qr-code-detector branch from 3fb1088 to 14fbe63 Compare January 29, 2021 08:29
@Ziachnix
Copy link
Copy Markdown
Contributor Author

WIP: Sorry, something went wrong during the rebase

@Ziachnix Ziachnix force-pushed the feature/js-qr-code-detector branch from 14fbe63 to d6bd688 Compare January 29, 2021 08:54
- cherry picked commit to solve rebase error
@Ziachnix Ziachnix force-pushed the feature/js-qr-code-detector branch from d6bd688 to c22d409 Compare February 1, 2021 11:30
@asmorkalov
Copy link
Copy Markdown
Contributor

@Ziachnix Do you have progress with the PR?

Copy link
Copy Markdown
Member

@alalek alalek left a comment

Choose a reason for hiding this comment

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

Thank you for update!

@endcode

@note
It requires the [opencv_extra repository](https://github.com/opencv/opencv.git) located in your development environment.
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.

Please drop OPENCV_TEST_DATA_PATH changes from the patch

@asmorkalov
Copy link
Copy Markdown
Contributor

@Ziachnix Friendly reminder.

@alalek alalek merged commit 960f501 into opencv:3.4 Mar 13, 2021
@alalek alalek mentioned this pull request Mar 13, 2021
@Ziachnix
Copy link
Copy Markdown
Contributor Author

@Ziachnix Friendly reminder.

Thank you, i totally forgot that there is still some work to be done.
I will open a new pull request when the tutorial page is ready to be merged.

@alalek alalek mentioned this pull request Apr 9, 2021
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.

3 participants