opencv.js icon indicating copy to clipboard operation
opencv.js copied to clipboard

Opencv.js latest build version can not work on the web worker

Open dzung-bes opened this issue 3 years ago • 8 comments

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 🙏

dzung-bes avatar Mar 05 '21 03:03 dzung-bes

Hi,

What's the error look like? I didn't try to run OpenCV.js in worker before.

huningxin avatar Mar 05 '21 05:03 huningxin

@huningxin thanks for your response. Please see my attachment: Screen Shot 2021-03-05 at 15 11 02

dzung-bes avatar Mar 05 '21 08:03 dzung-bes

Is this related to this issue? https://github.com/opencv/opencv/issues/19243#issuecomment-773217237

boulabiar avatar Mar 05 '21 10:03 boulabiar

@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 🙏

dzung-bes avatar Mar 08 '21 08:03 dzung-bes

@boulabiar Are you running the OpenCV on the main thread of the browser?

dzung-bes avatar Mar 08 '21 08:03 dzung-bes

@dzung-bes yes. It works fine with OpenCV 4.2, but not with 4.4

boulabiar avatar Mar 08 '21 09:03 boulabiar

@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 😂

dzung-bes avatar Mar 09 '21 02:03 dzung-bes

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:

  1. 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

  1. 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.

rubuslab avatar Aug 11 '21 08:08 rubuslab