Skip to content

Opencv.js: on imread add willReadFrequently to getContext#22613

Merged
asmorkalov merged 1 commit intoopencv:4.xfrom
erasta:patch-1
Oct 11, 2022
Merged

Opencv.js: on imread add willReadFrequently to getContext#22613
asmorkalov merged 1 commit intoopencv:4.xfrom
erasta:patch-1

Conversation

@erasta
Copy link
Copy Markdown
Contributor

@erasta erasta commented Oct 8, 2022

On opencv.js, cv.imread on a canvas element first gets the 2d context by getContext('2d').
This produces the warning on Chrome (and other webkit browsers):

Canvas2D: Multiple readback operations using getImageData are faster with the willReadFrequently attribute set to true.
See: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently

The link: https://html.spec.whatwg.org/multipage/canvas.html#concept-canvas-will-read-frequently
The correct syntax: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#syntax
The compatibility: https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/getContext#browser_compatibility

In this PR i added the willReadFrequently attribute and checked on Chrome (compatible), Safari (not compatible) and other browsers.
On compatible browsers the warning is avoided and imread should work faster.
On non-compatible browsers the change has no effect and imread works as before.

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 another license that is incompatible with OpenCV
  • The PR is proposed to the proper branch
  • There is a reference to the 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

@asmorkalov asmorkalov added this to the 4.7.0 milestone Oct 8, 2022
@asmorkalov asmorkalov self-assigned this Oct 11, 2022
@asmorkalov asmorkalov merged commit 1c825dd into opencv:4.x Oct 11, 2022
@alalek alalek mentioned this pull request Jan 8, 2023
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