opencv-wasm icon indicating copy to clipboard operation
opencv-wasm copied to clipboard

Is web environment supported?

Open ngocdaothanh opened this issue 4 years ago • 7 comments

The README says "Precompiled OpenCV to JavaScript + WebAssembly for node.js and deno environment", but is web environment supported?

If not, will opencv-wasm also add support for web soon (and is it hard to do)?

ngocdaothanh avatar Jan 19 '21 01:01 ngocdaothanh

Hello, currently, I designated this repo to make importing OpenCV.js in node.js and deno easy.

For the web browser, you can actually use directly the OpenCV.js that's provided from their website: https://docs.opencv.org/3.4/d0/d84/tutorial_js_usage.html

If you meant making this package (opencv-wasm) compatible with bundler tools (e.g., webpack), I'd need to work on that and make sure that it's integrated smoothly. But I couldn't give you a time estimation on when I'll do that. 🙏

echamudi avatar Jan 19 '21 18:01 echamudi

you can actually use directly the OpenCV.js that's provided from their website: https://docs.opencv.org/3.4/d0/d84/tutorial_js_usage.html

I think opencv.js (like https://docs.opencv.org/3.4.0/opencv.js) is asm.js, not WebAssembly?

ngocdaothanh avatar Jan 19 '21 18:01 ngocdaothanh

Aha yeah, just checked the file (https://docs.opencv.org/3.4.0/opencv.js), it doesn't use WebAssembly.

Compiling to the Wasm version wouldn't be complicated though. You can do it yourself by following this tutorial https://docs.opencv.org/4.3.0/d4/da1/tutorial_js_setup.html. The key is using the --build_wasm option.

echamudi avatar Jan 20 '21 02:01 echamudi

I'm new to WASM, so sorry for my curiosity:

  • What's the difference between the result of this GitHub project, and the result created by https://docs.opencv.org/4.3.0/d4/da1/tutorial_js_setup.html ?
  • What's the difference between running WASM in web browser, and in Nodejs?

ngocdaothanh avatar Jan 20 '21 04:01 ngocdaothanh

What's the difference between the result of this GitHub project, and the result created by https://docs.opencv.org/4.3.0/d4/da1/tutorial_js_setup.html ?

The opencv-wasm npm module is the result of the tutorial above + some changes in the flag + some addition in the JS code. Therefore, you can install OpenCV Wasm easily in your Node.js project by npm install opencv-wasm or in deno by importing the deno module.

What's the difference between running WASM in web browser, and in Nodejs?

The produced Wasm from the tutorial above can run in Node.js and web browser. But of course, in Node.js you get file system access.

echamudi avatar Jan 21 '21 01:01 echamudi

FYI (semi-related): There is some discussion on the official opencv repo around making a web-friendly npm packaged version in https://github.com/opencv/opencv/issues/15315

0xdevalias avatar Jun 13 '21 00:06 0xdevalias

Thanks @0xdevalias for informing me! It seems there is a lot of demand for it. I'll certainly work on it when I get time to do it. 😃

echamudi avatar Jun 14 '21 12:06 echamudi