opencv icon indicating copy to clipboard operation
opencv copied to clipboard

Why user builded the opencv.js can not use in html page directly.

Open leogitpro opened this issue 3 years ago • 7 comments

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.

leogitpro avatar Feb 08 '22 13:02 leogitpro

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 avatar Feb 23 '22 07:02 lovelyun

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
}

sfornengo avatar Mar 30 '22 13:03 sfornengo

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 avatar Nov 27 '23 10:11 simonbuehler

@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 avatar Nov 30 '23 09:11 activeguild

@activeguild see the issue #24620 , got help from a emscripten issue and a solution for it

simonbuehler avatar Nov 30 '23 09:11 simonbuehler

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

simonbuehler avatar Nov 30 '23 09:11 simonbuehler

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

ttt43ttt avatar Feb 12 '24 16:02 ttt43ttt

I also faced this issue :( how can we solve this problem?

hieunguyen2211 avatar Jun 10 '24 11:06 hieunguyen2211

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

opencv-alalek avatar Jun 10 '24 23:06 opencv-alalek