opencv.js
opencv.js copied to clipboard
Opencv.js latest build version can not work on the web worker
Hi @huningxin hu
I am trying to do some experiments with Opencv.js and web worker. What I did clone OpenCV to my machine, run docker to build opencv.js as official docs tutorials (https://docs.opencv.org/3.4.13/d4/da1/tutorial_js_setup.html). But when I tried to copy the file opencv.js and loaded it in the worker.js file by importScripts
, it failed. Do you have any experience with this problem? If yes, I really appreciate it if you could let me know what I am doing wrong.
Thank you 🙏
Hi,
What's the error look like? I didn't try to run OpenCV.js in worker before.
@huningxin thanks for your response. Please see my attachment:
Is this related to this issue? https://github.com/opencv/opencv/issues/19243#issuecomment-773217237
@huningxin btw, I found that your built version can work on web worker as my expectation. Can you share with me which parameters are you using to build opencv.js and opencv.wasm? I can try to compare and investigate the problem by my self. Thanks 🙏
@boulabiar Are you running the OpenCV on the main thread of the browser?
@dzung-bes yes. It works fine with OpenCV 4.2, but not with 4.4
@boulabiar I try to build opencv.js without docker and it works fine too. But there is a warning SharedArrayBuffer will require cross-origin isolation as of M91, around May 2021.
showed in the debug tool 😂
I think the key point is how to install build tool emscripten correctly. I installed emscripten-1.39.12 and can build latest opencv output to wasm success. steps as below:
- install emscripten-1.39.12 and refine configuration (my main folder /data/develop-003/) rm /root/.emscripten* -rf git clone -b 1.39.12 https://github.com/emscripten-core/emsdk.git cd emsdk ./emsdk install 1.39.12 ./emsdk activate 1.39.12 cp /root/.emscripten ./ source ./emsdk_env.sh
// test command ./upstream/emscripten/emcc -v
- clone opencv latest and build wasm js git clone https://github.com/opencv/opencv.git cd opencv python3 ./platforms/js/build_js.py build_wasm_out --build_wasm --emscripten_dir=/data/develop-003/emsdk/upstream/emscripten/
I also built opencv-4.3.0(git clone -b 4.3.0 https://github.com/opencv/opencv.git) success. May this can help you.