opencv
opencv copied to clipboard
Why user builded the opencv.js can not use in html page directly.
I have build a javascript opencv.js for my web page. build process is successful. when add it script to html, onload callback debug log the cv is a promise. But use the official link: https://docs.opencv.org/4.5.5/opencv.js, all of is OK. Is any steps missed? the build guidance is ref from https://docs.opencv.org/4.5.5/d4/da1/tutorial_js_setup.html Thanks very much.
It's same to me that cv is a promise,you can try to reset cv.
<script src="js/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
async function onOpenCvReady() { window.cv = await window.cv }
In order to use the generated opencv.js directly in the html page as the official link https://docs.opencv.org/4.5.5/opencv.js, I must replace in the latest lines:
return cv.ready
}
by:
return cv
}
this seems to be only a half-baked workaround, now while it loads - when using imread
it fails with
Uncaught TypeError: cv.matFromImageData is not a function
imread http://localhost:5173/opencv.js:5931
so the problem is that now inside the opencv.js cv
is not the full object:
function cv(moduleArg)
arguments: null
caller: null
length: 0
name: ""
prototype: Object { … }
<prototype>: function ()
i'm really struggling to get a self build opencv.js ( with wasm) to just work, any hints?
@simonbuehler
The error seems to be due to referencing cv
in the local scope, you can avoid the error by converting cv
to window.cv
in the js file. No drastic solution is known.
@activeguild see the issue #24620 , got help from a emscripten issue and a solution for it
It's same to me that cv is a promise,you can try to reset cv.
<script src="js/opencv.js" onload="onOpenCvReady();" type="text/javascript"></script>
async function onOpenCvReady() { window.cv = await window.cv }
@lovelyun do you actually know what triggered that change in the behaviour (cv beeing a promise) ? There are lots of usages of "cv" in the code that do expect the settled object and not the promise
I have the same issue. What's the command line to reproduce the same opencv.js
file as the official release? It's not documented in https://docs.opencv.org/4.9.0/d4/da1/tutorial_js_setup.html
I also faced this issue :( how can we solve this problem?
June 2024 (OpenCV 4.10.0):
- docs.opencv.org uses legacy CI builder: https://pullrequest.opencv.org/buildbot/builders/4_x-contrib_docs-lin64/builds/100773 (used version is
EMSDK_VERSION=1.39.0-upstream
) - modern GitHub Actions CI builder is WIP here: https://github.com/opencv/ci-gha-workflow/pull/174